Parcourir la source

added file picker to gui

Cyamond il y a 4 ans
Parent
commit
8c14dac870

+ 2 - 0
gui/CMakeLists.txt

@@ -5,6 +5,8 @@ project(CCats-GUI LANGUAGES CXX)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 find_package(Threads)
 find_package(Boost 1.67 REQUIRED COMPONENTS system)

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

@@ -0,0 +1,28 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.5
+
+Page {
+    width: 1280
+    height: 670
+    title: "Receiving"
+
+    Label {
+        color: "#000000"
+        text: "Why are we not using C# :/"
+        font.pointSize: 30
+        anchors.verticalCenterOffset: 1
+        anchors.horizontalCenterOffset: 1
+        z: 3
+        anchors.centerIn: parent
+    }
+
+    Rectangle {
+        id: rectangle
+        x: 0
+        y: 0
+        width: 1280
+        height: 670
+        color: "#ffffff"
+        z: 2
+    }
+}

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

@@ -0,0 +1,50 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.5
+import QtQuick.Dialogs 1.0
+
+Page {
+    width: 1280
+    height: 670
+
+    title: qsTr("Sending")
+
+    Connections {
+      target: _qmlHandler
+      onSetFileUrlText: {
+        fileUrlText.text = signalText
+      }
+    }
+
+    Button {
+        id: selectFileButton
+        x: 510
+        y: 291
+        width: 260
+        height: 89
+        text: qsTr("Select File")
+        font.pointSize: 16
+        onClicked: {fileDialog.open()}
+    }
+
+    Text {
+        id: fileUrlText
+        x: 54
+        y: 427
+        width: 1172
+        height: 52
+        color: "#ffffff"
+        text: qsTr("")
+        verticalAlignment: Text.AlignVCenter
+        horizontalAlignment: Text.AlignHCenter
+        font.pixelSize: 23
+    }
+
+    FileDialog {
+      id: fileDialog
+      title: "Please choose a file"
+      folder: shortcuts.home
+      onAccepted: {
+        _qmlHandler.onSelectFile(fileDialog.fileUrl)
+      }
+    }
+}

+ 11 - 12
gui/src/main.cpp

@@ -1,6 +1,8 @@
 #include <QGuiApplication>
 #include <QObject>
 #include <QQmlApplicationEngine>
+#include <QQmlComponent>
+#include <QQmlContext>
 #include <csignal>
 #include <cstdio>
 #include <cstdlib>
@@ -18,6 +20,8 @@ int outpipefd[2];
 char buf[1024];
 
 int main(int argc, char *argv[]) {
+  qInfo() << "Program Start";
+
   pid_t pid = 0;
   char msg[256];
   int status;
@@ -45,29 +49,24 @@ int main(int argc, char *argv[]) {
   close(outpipefd[0]);
   close(inpipefd[1]);
 
-  // ########## GUI CODE ##########
+  // ########## Load GUI ##########
 
   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
+  //This has to be here to fix warnings
+  QCoreApplication::setOrganizationName("CCats");
+
   QGuiApplication app(argc, argv);
 
   QQmlApplicationEngine engine;
-  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
-
-  if (engine.rootObjects().isEmpty())
-    return -1;
 
   QMLHandler qmlHandler;
 
-  QObject *statusButton =
-      engine.rootObjects().first()->findChild<QObject *>("getstatusbutton");
+  engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
 
-  QObject::connect(statusButton, SIGNAL(clicked()), &qmlHandler,
-                   SLOT(onGetStatusClick()));
+  QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
 
-  QObject::connect(&qmlHandler, SIGNAL(setStatusMessage(QVariant)),
-                   engine.rootObjects().first(),
-                   SLOT(setStatusMessage(QVariant)));
+  QObject *object = component.create();
 
   return app.exec();
 }

+ 46 - 29
gui/src/main.qml

@@ -1,40 +1,57 @@
-import QtQuick 2.9
-import QtQuick.Window 2.2
-import QtQuick.Controls 1.5
+import QtQuick 2.12
+import QtQuick.Controls 2.5
 
-Window {
+ApplicationWindow {
+    id: window
     visible: true
     width: 1280
     height: 720
-    color: "#191919"
-    title: qsTr("Covert Channel | Control Panel")
+    title: qsTr("Covert Channel - Control Panel")
 
-    function setStatusMessage(text) {
-        statusmessage.text = text
+    header: ToolBar {
+        contentHeight: 50
+
+        ToolButton {
+            id: toolButton
+            text: stackView.depth > 1 ? "\u25C0" : "\u2630"
+            font.pixelSize: Qt.application.font.pixelSize * 1.6
+            onClicked: {
+                if (stackView.depth > 1) {
+                    stackView.pop()
+                } else {
+                    drawer.open()
+                }
+            }
+        }
+
+        Label {
+            text: stackView.currentItem.title
+            anchors.centerIn: parent
+        }
     }
 
-    Text {
-        id: statusmessage
-        objectName: "statusmessage"
-        x: 210
-        y: 583
-        width: 861
-        height: 109
-        color: "#ffffff"
-        text: qsTr("")
-        font.family: "Courier"
-        horizontalAlignment: Text.AlignHCenter
-        fontSizeMode: Text.FixedSize
-        font.pixelSize: 59
+    Drawer {
+        id: drawer
+        width: window.width * 0.66
+        height: 50
+
+        Column {
+            anchors.fill: parent
+
+            ItemDelegate {
+                text: qsTr("Receiving")
+                width: parent.width
+                onClicked: {
+                    stackView.push("ReceivingForm.ui.qml")
+                    drawer.close()
+                }
+            }
+        }
     }
 
-    Button {
-        id: getstatusbutton
-        objectName: "getstatusbutton"
-        x: 504
-        y: 183
-        width: 273
-        height: 73
-        text: qsTr("Get Daemon Status")
+    StackView {
+        id: stackView
+        initialItem: "SendingForm.ui.qml"
+        anchors.fill: parent
     }
 }

+ 3 - 0
gui/src/qml.qrc

@@ -1,5 +1,8 @@
 <RCC>
     <qresource prefix="/">
         <file>main.qml</file>
+        <file>SendingForm.ui.qml</file>
+        <file>ReceivingForm.ui.qml</file>
+        <file>qtquickcontrols2.conf</file>
     </qresource>
 </RCC>

+ 9 - 11
gui/src/qmlhandler.cpp

@@ -1,17 +1,15 @@
 #include "qmlhandler.h"
+#include <string>
 
-#include <unistd.h>
+using namespace std;
 
-extern int inpipefd[2];
-extern int outpipefd[2];
-extern char buf[1024];
+string fileUrl;
 
 QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 
-void QMLHandler::onGetStatusClick() {
-  read(inpipefd[0], buf, 1024);
-  buf[1023] = 0;
-  buf[strlen(buf)] = 0;
-  qInfo() << buf;
-  emit setStatusMessage("Check Terminal plz");
-}
+void QMLHandler::onSelectFile(QUrl url) {
+  qInfo() << "File Selected: " << url.toString();
+  emit setFileUrlText("Selected File: " + url.toString());
+  
+  fileUrl = url.toString().toStdString();
+}

+ 3 - 2
gui/src/qmlhandler.h

@@ -3,6 +3,7 @@
 
 #include <QDebug>
 #include <QObject>
+#include <QUrl>
 
 class QMLHandler : public QObject {
   Q_OBJECT
@@ -11,10 +12,10 @@ public:
   explicit QMLHandler(QObject *parent = 0);
 
 signals:
-  void setStatusMessage(QVariant text);
+  void setFileUrlText(QString signalText);
 
 public slots:
-  void onGetStatusClick();
+  void onSelectFile(QUrl url);
 };
 
 #endif // CCATS_GUI_QMLHANDLER_H

+ 13 - 0
gui/src/qtquickcontrols2.conf

@@ -0,0 +1,13 @@
+; This file can be edited to change the style of the application
+; Read "Qt Quick Controls 2 Configuration File" for details:
+; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html
+
+[Controls]
+Style=Material
+
+[Material]
+Theme=Dark
+;Accent=BlueGrey
+;Primary=BlueGray
+;Foreground=Brown
+;Background=Grey