Переглянути джерело

US45.3: Extended list command (GUI)

Sander, Paul 4 роки тому
батько
коміт
5212f5f92b

+ 1 - 0
gui/include/cmdmanager.h

@@ -19,6 +19,7 @@ void handleError(Json::Value root);
 void handleStatus(Json::Value root);
 void handleClose(Json::Value root);
 void handleList(Json::Value root);
+void handleExtendedList(Json::Value root);
 void handleConnect(Json::Value root);
 void handleVersion(Json::Value root);
 void handleLogin(Json::Value root);

+ 2 - 1
gui/include/qmlhandler.h

@@ -41,7 +41,8 @@ signals:
 
 	// Receiving
 	void receivingClearFileList();
-	void receivingListFile(QString fileName, bool existsLocally);
+	void receivingListFile(QString fileName, QString fileSize, QString fileDecryptable, bool existsLocally);
+	void receivingUpdateFile(QString fileName, QString fileProgress, bool isQueued);
 	void receivingDisableDownloadButton(QString fileName);
 	void receivingCloseConfirmDeletePopup();
 

+ 33 - 15
gui/src/Forms/Receiving/ReceivingFileTemplate.ui.qml

@@ -7,8 +7,10 @@ Item {
     height: 50
     property string fileNameText: "Name Placeholder"
     property string fileSizeText: "Size Placeholder"
+    property string fileProgressText: "Progress Placeholder"
     property string fileDecryptableText: "Decryptable Placeholder"
     property bool fileExists: false
+    property bool fileQueued: false
 
     Connections {
         target: _qmlHandler
@@ -49,34 +51,42 @@ Item {
         }
 
         Text {
-            id: fileTemplateFileDecryptable
+            id: fileTemplateFileProgress
             Layout.alignment: Qt.AlignCenter
             Layout.preferredHeight: parent.height
-            Layout.preferredWidth: 150
+            Layout.preferredWidth: 100
             verticalAlignment: Text.AlignVCenter
             horizontalAlignment: Text.AlignHCenter
-            text: fileDecryptableText
+            text: fileProgressText
             color: "#ffffff"
         }
 
-        Button {
-            id: fileTemplateQueueButton
+        Text {
+            id: fileTemplateFileDecryptable
             Layout.alignment: Qt.AlignCenter
             Layout.preferredHeight: parent.height
-            Layout.preferredWidth: 100
-            text: qsTr("Enqueue")
-
-            onClicked: _qmlHandler.onReceivingQueueFileButton(fileNameText)
+            Layout.preferredWidth: 150
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
+            text: fileDecryptableText
+            color: "#ffffff"
         }
 
         Button {
-            id: fileTemplateDequeueButton
+            id: fileTemplateQueueButton
             Layout.alignment: Qt.AlignCenter
             Layout.preferredHeight: parent.height
             Layout.preferredWidth: 100
-            text: qsTr("Dequeue")
-
-            onClicked: _qmlHandler.onReceivingDequeueFileButton(fileNameText)
+            text: fileQueued ? qsTr("Dequeue") : qsTr("Enqueue")
+
+            // @disable-check M223
+            onClicked: {
+                // @disable-check M222
+                fileQueued ? _qmlHandler.onReceivingDequeueFileButton(
+                                 // @disable-check M222
+                                 fileNameText) : _qmlHandler.onReceivingQueueFileButton(
+                                 fileNameText)
+            }
         }
 
         Button {
@@ -87,7 +97,11 @@ Item {
             enabled: !fileExists
             text: fileExists ? qsTr("Already Downloaded") : qsTr("Download")
 
-            onClicked: _qmlHandler.onReceivingDownloadFileButton(fileNameText)
+            // @disable-check M223
+            onClicked: {
+                // @disable-check M222
+                _qmlHandler.onReceivingDownloadFileButton(fileNameText)
+            }
         }
 
         Button {
@@ -97,7 +111,11 @@ Item {
             Layout.preferredWidth: 200
             text: qsTr("Delete from server")
 
-            onClicked: confirmDeletePopup.open()
+            // @disable-check M223
+            onClicked: {
+                // @disable-check M222
+                confirmDeletePopup.open()
+            }
         }
     }
 

+ 8 - 3
gui/src/Forms/Receiving/ReceivingForm.ui.qml

@@ -14,8 +14,9 @@ Page {
         onReceivingListFile: {
             fileList.append({
                                 "fileName": fileName,
-                                "fileSize": "42 kb",
-                                "fileDecryptable": "Decryptable?: Yes",
+                                "fileSize": fileSize + " kb",
+                                "fileProgress": "",
+                                "fileDecryptable": fileDecryptable,
                                 "fileExistsLocally": existsLocally
                             })
         }
@@ -40,6 +41,7 @@ Page {
                 delegate: ReceivingFileTemplate {
                     fileNameText: fileName
                     fileSizeText: fileSize
+                    fileProgressText: fileProgress
                     fileDecryptableText: fileDecryptable
                     fileExists: fileExistsLocally
                 }
@@ -62,10 +64,13 @@ Page {
 
                 // @disable-check M223
                 onClicked: {
-                    // @disable-check M223
+                    // @disable-check M222
                     _qmlHandler.onReceivingListFilesButton()
                 }
             }
         }
     }
 }
+
+
+

+ 35 - 12
gui/src/cmdmanager.cpp

@@ -23,6 +23,7 @@ void CmdManager::init() {
 	cmdmap["status"] = &CmdManager::handleStatus;
 	cmdmap["close"] = &CmdManager::handleClose;
 	cmdmap["list"] = &CmdManager::handleList;
+	cmdmap["extendedlist"] = &CmdManager::handleExtendedList;
 	cmdmap["connect"] = &CmdManager::handleConnect;
 	cmdmap["version"] = &CmdManager::handleVersion;
 	cmdmap["login"] = &CmdManager::handleLogin;
@@ -55,13 +56,33 @@ void CmdManager::handleStatus(Json::Value root) { emit qmlHandler->footerSetStat
 void CmdManager::handleClose(Json::Value root) { CliManager::setProgramActive(false); }
 
 void CmdManager::handleList(Json::Value root) {
+	char sizebuf[256];
+	snprintf(sizebuf, 256, "%.2f", 4.2f);
 	if (root["accept"] == true) {
 		emit qmlHandler->receivingClearFileList();
 
 		// Get the array of file Names
 		auto fileNames = root["names"];
 		for (int i = 0; i < fileNames.size(); i++) {
-			emit qmlHandler->receivingListFile(QString::fromStdString(fileNames[i].asString().c_str()), boost::filesystem::exists(fileNames[i].asString()));
+			emit qmlHandler->receivingListFile(QString::fromStdString(fileNames[i].asString()), QString::fromStdString(sizebuf), QString("Decryptable"),
+			                                   boost::filesystem::exists(fileNames[i].asString()));
+		}
+	} else {
+		emit qmlHandler->log(root["error"].asString().c_str());
+	}
+}
+
+void CmdManager::handleExtendedList(Json::Value root) {
+	char sizebuf[256];
+	if (root["accept"] == true) {
+		emit qmlHandler->receivingClearFileList();
+
+		// Get the array of file Names
+		auto files = root["files"];
+		for (Json::Value f : files) {
+			snprintf(sizebuf, 256, "%.2f", f["size"].asFloat());
+			emit qmlHandler->receivingListFile(QString::fromStdString(f["name"].asString()), QString::fromStdString(sizebuf),
+			                                   QString::fromStdString(f["encrypted"].asString()), boost::filesystem::exists(f["name"].asString()));
 		}
 	} else {
 		emit qmlHandler->log(root["error"].asString().c_str());
@@ -90,7 +111,7 @@ void CmdManager::handleVersion(Json::Value root) {
 void CmdManager::handleLogin(Json::Value root) {
 	if (root["accept"] == true) {
 		emit qmlHandler->loginSignupPopupClose();
-		CliManager::writeToCli("list");
+		CliManager::writeToCli("extendedlist");
 		qmlHandler->loadSettingsToGUI();
 	} else {
 		emit qmlHandler->loginSetStatus(root["error"].asString().c_str());
@@ -156,17 +177,19 @@ void CmdManager::handleDeleteFile(Json::Value root) {
 
 void CmdManager::handleNotifications(Json::Value root) {
 	if (root["accept"] == true) {
-		// Get the array of notifications
-		auto notifications = root["messages"];
-		for (int i = 0; i < notifications.size(); i++) {
-			emit qmlHandler->notification(QString::fromStdString(notifications[i].asString().c_str()));
+		if (!root["messages"].isNull()) {
+			// Get the array of notifications
+			auto notifications = root["messages"];
+			for (int i = 0; i < notifications.size(); i++) {
+				emit qmlHandler->notification(QString::fromStdString(notifications[i].asString()));
+			}
+
+			if (notifications.size() > 1)
+				emit qmlHandler->showDesktopNotification("Covert Channel - New Notifications",
+				                                         "You have multiple new notifications. Open the program to see them.");
+			else if (notifications.size() == 1)
+				emit qmlHandler->showDesktopNotification("Covert Channel - New Notification", QString::fromStdString(notifications[0].asString()));
 		}
-
-		if (notifications.size() > 1)
-			emit qmlHandler->showDesktopNotification("Covert Channel - New Notifications",
-			                                         "You have multiple new notifications. Open the program to see them.");
-		else if (notifications.size() == 1)
-			emit qmlHandler->showDesktopNotification("Covert Channel - New Notification", QString::fromStdString(notifications[0].asString().c_str()));
 	} else {
 		emit qmlHandler->log(root["error"].asString().c_str());
 	}

+ 1 - 1
gui/src/qmlhandler.cpp

@@ -118,7 +118,7 @@ void QMLHandler::onSendingClearSelectionButton() {
 }
 
 // Receiving
-void QMLHandler::onReceivingListFilesButton() { CliManager::writeToCli("list"); }
+void QMLHandler::onReceivingListFilesButton() { CliManager::writeToCli("extendedlist"); }
 
 void QMLHandler::onReceivingDownloadFileButton(QString fileName) {
 	QString command = "get " + fileName;