Browse Source

Update QR code on connection

pull/45/head
Aditya Kulkarni 5 years ago
parent
commit
1b938928e2
  1. 10
      src/mobileappconnector.ui
  2. 42
      src/websockets.cpp
  3. 1
      src/websockets.h

10
src/mobileappconnector.ui

@ -43,16 +43,6 @@
<string>QR Code</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="lblConnStr">
<property name="text">
<string>Connection URI String</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRCodeLabel" name="qrcode">
<property name="sizePolicy">

42
src/websockets.cpp

@ -95,6 +95,26 @@ void AppDataServer::connectAppDialog(QWidget* parent) {
ui->setupUi(&d);
Settings::saveRestore(&d);
updateUIWithNewQRCode();
updateConnectedUI();
QObject::connect(ui->btnDisconnect, &QPushButton::clicked, [=] () {
QSettings().setValue("mobileapp/connectedname", "");
saveNewSecret("");
updateConnectedUI();
});
d.exec();
// Cleanup
tempSecret = "";
delete ui;
ui = nullptr;
}
void AppDataServer::updateUIWithNewQRCode() {
// Get the address of the localhost
auto addrList = QNetworkInterface::allAddresses();
@ -124,25 +144,7 @@ void AppDataServer::connectAppDialog(QWidget* parent) {
QString codeStr = uri + "," + secretStr;
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() {
@ -337,7 +339,11 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
// If the Connection UI is showing, we have to update the UI as well
if (ui != nullptr) {
// Update the connected phone information
updateConnectedUI();
// Update with a new QR Code for safety, so this secret isn't used by anyone else
updateUIWithNewQRCode();
}
}
}

1
src/websockets.h

@ -42,6 +42,7 @@ class AppDataServer {
public:
static void connectAppDialog(QWidget* parent);
static void updateConnectedUI();
static void updateUIWithNewQRCode();
static void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QWebSocket* pClient);
static void processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);

Loading…
Cancel
Save