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