|
@@ -22,8 +22,8 @@ int inpipefd[2];
|
|
|
int outpipefd[2];
|
|
|
char buf[1025];
|
|
|
QUrl sendFileUrl = QUrl("");
|
|
|
-QString _USERNAME;
|
|
|
-QString _PASSWORD;
|
|
|
+QString _IP = qsTr("");
|
|
|
+bool _CLI_RUNNING = false;
|
|
|
|
|
|
bool programActive = true;
|
|
|
|
|
@@ -74,34 +74,38 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
else if (cmd.compare("connect")) {
|
|
|
if (root["accept"] == false) {
|
|
|
emit ipPopupSetStatus(root["error"].asString().c_str());
|
|
|
- close(outpipefd[1]);
|
|
|
- close(inpipefd[0]);
|
|
|
+ reopenCLI(_IP);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (cmd.compare("version")) {
|
|
|
if (root["accept"] == true) {
|
|
|
- write(outpipefd[1], _USERNAME.toUtf8().constData(),
|
|
|
- strlen(_USERNAME.toUtf8().constData()));
|
|
|
- write(outpipefd[1], _PASSWORD.toUtf8().constData(),
|
|
|
- strlen(_PASSWORD.toUtf8().constData()));
|
|
|
+ emit ipPopupClose();
|
|
|
+ emit loginSignupPopupOpen();
|
|
|
} else {
|
|
|
QString errorMessage = QString::fromStdString(string(
|
|
|
"Version mismatch: \nClient: " + root["clientversion"].asString() +
|
|
|
"\nServer: " + root["serverversion"].asString()));
|
|
|
emit ipPopupSetStatus(errorMessage);
|
|
|
- close(outpipefd[1]);
|
|
|
- close(inpipefd[0]);
|
|
|
+ reopenCLI(_IP);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (cmd.compare("login")) {
|
|
|
if (root["accept"] == true) {
|
|
|
- emit ipPopupClose();
|
|
|
+ emit loginSignupPopupClose();
|
|
|
} else {
|
|
|
- emit ipPopupSetStatus(root["error"].asString().c_str());
|
|
|
- close(outpipefd[1]);
|
|
|
- close(inpipefd[0]);
|
|
|
+ emit loginSetStatus(root["error"].asString().c_str());
|
|
|
+ reopenCLI(_IP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("signup")) {
|
|
|
+ if (root["accept"] == true) {
|
|
|
+ emit loginSignupPopupClose();
|
|
|
+ } else {
|
|
|
+ emit loginSetStatus(root["error"].asString().c_str());
|
|
|
+ reopenCLI(_IP);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -211,7 +215,38 @@ void QMLHandler::onSettingsSwitchServerButton() {
|
|
|
}
|
|
|
|
|
|
// Ip Popup
|
|
|
-void QMLHandler::onIpPopupConnectButton(QString ip) {
|
|
|
+void QMLHandler::onIpPopupConnectButton(QString ip) { reopenCLI(ip); }
|
|
|
+
|
|
|
+// Login
|
|
|
+void QMLHandler::onLoginLoginButton(QString username, QString password) {
|
|
|
+ QString command = "login " + username + " " + password + "\n";
|
|
|
+ write(outpipefd[1], command.toUtf8().constData(),
|
|
|
+ strlen(command.toUtf8().constData()));
|
|
|
+}
|
|
|
+
|
|
|
+// Signup
|
|
|
+void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne,
|
|
|
+ QString passwordTwo) {
|
|
|
+ if (QString::compare(passwordOne, passwordTwo, Qt::CaseSensitive)) {
|
|
|
+ emit signupSetStatus("Passwords don't match");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QString command = "signup " + username + " " + passwordOne + "\n";
|
|
|
+ write(outpipefd[1], command.toUtf8().constData(),
|
|
|
+ strlen(command.toUtf8().constData()));
|
|
|
+}
|
|
|
+
|
|
|
+// Footer
|
|
|
+void QMLHandler::onFooterGetStatusButton() {
|
|
|
+ write(outpipefd[1], "status\n", strlen("status\n"));
|
|
|
+}
|
|
|
+
|
|
|
+void QMLHandler::reopenCLI(QString ip) {
|
|
|
+ if (_CLI_RUNNING) {
|
|
|
+ closeCLI();
|
|
|
+ }
|
|
|
+
|
|
|
+ _IP = ip;
|
|
|
pid_t pid = 0;
|
|
|
|
|
|
pipe(inpipefd);
|
|
@@ -231,25 +266,18 @@ void QMLHandler::onIpPopupConnectButton(QString ip) {
|
|
|
execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
|
|
|
"--machine", (char *)NULL);
|
|
|
|
|
|
+ _CLI_RUNNING = true;
|
|
|
+
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
- // TODO: Not hardcoded
|
|
|
- emit footerSetStatus("Connected to " + ip);
|
|
|
-
|
|
|
close(outpipefd[0]);
|
|
|
close(inpipefd[1]);
|
|
|
|
|
|
std::thread(&QMLHandler::readPipeLoop, this).detach();
|
|
|
}
|
|
|
|
|
|
-// Login
|
|
|
-void QMLHandler::onLoginLoginButton(QString username, QString password) {}
|
|
|
-
|
|
|
-// Signup
|
|
|
-void QMLHandler::onSignupRegisterButton(QString username, QString password) {}
|
|
|
-
|
|
|
-// Footer
|
|
|
-void QMLHandler::onFooterGetStatusButton() {
|
|
|
- write(outpipefd[1], "status\n", strlen("status\n"));
|
|
|
+void QMLHandler::closeCLI() {
|
|
|
+ close(outpipefd[1]);
|
|
|
+ close(inpipefd[0]);
|
|
|
}
|