pairingpage.cpp raw
1 // Copyright (c) 2018 The Limenka developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #include <limenka-build-config.h> // IWYU pragma: keep
6
7 #include <qt/clientmodel.h>
8 #include <qt/pairingpage.h>
9 #include <qt/qrimagewidget.h>
10
11 #include <QFormLayout>
12 #include <QLabel>
13 #include <QLayout>
14 #include <QLineEdit>
15
16 PairingPage::PairingPage(QWidget *parent) :
17 QWidget(parent)
18 {
19 QVBoxLayout *layout = new QVBoxLayout(this);
20
21 QLabel *label_experimental = new QLabel(this);
22 label_experimental->setStyleSheet("QLabel { background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop:0 #F0D0A0, stop:1 #F8D488); color:#000000; }");
23 label_experimental->setMargin(3);
24 label_experimental->setTextInteractionFlags(Qt::TextSelectableByMouse);
25 label_experimental->setWordWrap(true);
26 label_experimental->setText(tr("Pairing is an experimental feature that currently only works when Tor is enabled. It is expected that the pairing address below will change with future updates, and you may need to re-pair after upgrading."));
27 layout->addWidget(label_experimental);
28
29 QLabel *label_summary = new QLabel(this);
30 label_summary->setText(tr("Below you will find information to pair other software or devices with this node:"));
31 layout->addWidget(label_summary);
32
33 QFormLayout *form_layout = new QFormLayout();
34 m_onion_address = new QLineEdit(this);
35 m_onion_address->setReadOnly(true);
36 form_layout->addRow(tr("Onion address: "), m_onion_address);
37
38 layout->addLayout(form_layout);
39
40 m_qrcode = new QRImageWidget(this);
41 #ifdef USE_QRCODE
42 layout->addWidget(m_qrcode);
43 #endif
44
45 layout->addStretch();
46
47 refresh();
48 }
49
50 void PairingPage::setClientModel(ClientModel *client_model)
51 {
52 if (m_client_model) {
53 disconnect(m_client_model, &ClientModel::networkLocalChanged, this, &PairingPage::refresh);
54 }
55 m_client_model = client_model;
56 if (client_model) {
57 connect(client_model, &ClientModel::networkLocalChanged, this, &PairingPage::refresh);
58 }
59 refresh();
60 }
61
62 void PairingPage::refresh()
63 {
64 QString onion;
65 if (m_client_model && m_client_model->getTorInfo(onion)) {
66 m_onion_address->setText(onion);
67 m_onion_address->setEnabled(true);
68 QString uri = QString("limenka-p2p://") + onion;
69 m_qrcode->setQR(uri);
70 m_qrcode->setVisible(true);
71 } else {
72 m_onion_address->setText(tr("(not connected)"));
73 m_onion_address->setEnabled(false);
74 m_qrcode->setVisible(false);
75 }
76 }
77