Fix up the connection UI
This commit is contained in:
@@ -78,21 +78,7 @@
|
||||
<string>ZecQT Wallet Companion App</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="btnDisconnect">
|
||||
<property name="text">
|
||||
<string>Disconnect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lblConnectedApp">
|
||||
<property name="text">
|
||||
<string>Connected Phone Name and Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -106,14 +92,20 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblRemoteNonce">
|
||||
<widget class="QPushButton" name="btnDisconnect">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Disconnect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblLocalNonce">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lblRemoteName">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
|
||||
@@ -86,12 +86,13 @@ void AppDataServer::saveNewSecret(QString secretHex) {
|
||||
s.sync();
|
||||
}
|
||||
|
||||
QString AppDataServer::tempSecret;
|
||||
QString AppDataServer::tempSecret = "";
|
||||
Ui_MobileAppConnector* AppDataServer::ui = nullptr;
|
||||
|
||||
void AppDataServer::connectAppDialog(QWidget* parent) {
|
||||
QDialog d(parent);
|
||||
Ui_MobileAppConnector con;
|
||||
con.setupUi(&d);
|
||||
ui = new Ui_MobileAppConnector();
|
||||
ui->setupUi(&d);
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
// Get the address of the localhost
|
||||
@@ -123,13 +124,34 @@ void AppDataServer::connectAppDialog(QWidget* parent) {
|
||||
|
||||
QString codeStr = uri + "," + secretStr;
|
||||
|
||||
con.lblConnStr->setText(codeStr);
|
||||
con.qrcode->setQrcodeString(codeStr);
|
||||
con.lblRemoteNonce->setText(AppDataServer::getNonceHex(NonceType::REMOTE));
|
||||
con.lblLocalNonce->setText(AppDataServer::getNonceHex(NonceType::LOCAL));
|
||||
ui->lblConnStr->setText(codeStr);
|
||||
ui->qrcode->setQrcodeString(codeStr);
|
||||
|
||||
updateConnectedUI();
|
||||
|
||||
QObject::connect(ui->btnDisconnect, &QPushButton::clicked, [=] () {
|
||||
QSettings().setValue("mobileapp/connectedname", "");
|
||||
saveNewSecret("");
|
||||
|
||||
updateConnectedUI();
|
||||
});
|
||||
|
||||
|
||||
d.exec();
|
||||
|
||||
// Cleanup
|
||||
tempSecret = "";
|
||||
delete ui;
|
||||
ui = nullptr;
|
||||
}
|
||||
|
||||
void AppDataServer::updateConnectedUI() {
|
||||
if (ui == nullptr)
|
||||
return;
|
||||
|
||||
auto remoteName = QSettings().value("mobileapp/connectedname", "").toString();
|
||||
ui->lblRemoteName->setText(remoteName.isEmpty() ? "(Not connected to any device)" : remoteName);
|
||||
ui->btnDisconnect->setEnabled(!remoteName.isEmpty());
|
||||
}
|
||||
|
||||
QString AppDataServer::getNonceHex(NonceType nt) {
|
||||
@@ -311,17 +333,20 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
||||
saveNewSecret(tempSecret);
|
||||
AppDataServer::saveNonceHex(NonceType::REMOTE, QString("00").repeated(24));
|
||||
|
||||
// Fall through to processDecryptedMessage
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
|
||||
// If the Connection UI is showing, we have to update the UI as well
|
||||
if (ui != nullptr) {
|
||||
updateConnectedUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
replyWithError();
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
}
|
||||
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
}
|
||||
|
||||
void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient) {
|
||||
@@ -338,7 +363,7 @@ void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWin
|
||||
}
|
||||
|
||||
if (msg.object()["command"] == "getInfo") {
|
||||
processGetInfo(mainWindow, pClient);
|
||||
processGetInfo(msg.object(), mainWindow, pClient);
|
||||
}
|
||||
else if (msg.object()["command"] == "getTransactions") {
|
||||
processGetTransactions(mainWindow, pClient);
|
||||
@@ -434,7 +459,14 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QW
|
||||
pClient->sendTextMessage(encryptOutgoing(r));
|
||||
}
|
||||
|
||||
void AppDataServer::processGetInfo(MainWindow* mainWindow, QWebSocket* pClient) {
|
||||
void AppDataServer::processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient) {
|
||||
auto connectedName = jobj["name"].toString();
|
||||
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue("mobileapp/connectedname", connectedName);
|
||||
}
|
||||
|
||||
auto r = QJsonDocument(QJsonObject{
|
||||
{"version", 1.0},
|
||||
{"command", "getInfo"},
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#ifndef WEBSOCKETS_H
|
||||
#define WEBSOCKETS_H
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mobileappconnector.h"
|
||||
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||
@@ -39,11 +41,12 @@ enum NonceType {
|
||||
class AppDataServer {
|
||||
public:
|
||||
static void connectAppDialog(QWidget* parent);
|
||||
static void updateConnectedUI();
|
||||
|
||||
static void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QWebSocket* pClient);
|
||||
static void processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
||||
static void processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
||||
static void processGetInfo(MainWindow* mainWindow, QWebSocket* pClient);
|
||||
static void processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient);
|
||||
static void processGetTransactions(MainWindow* mainWindow, QWebSocket* pClient);
|
||||
|
||||
static QString decryptMessage(QJsonDocument msg, QString secretHex, bool skipNonceCheck = false);
|
||||
@@ -57,6 +60,7 @@ public:
|
||||
|
||||
private:
|
||||
static QString tempSecret;
|
||||
static Ui_MobileAppConnector* ui;
|
||||
};
|
||||
|
||||
class AppDataModel {
|
||||
|
||||
Reference in New Issue
Block a user