feather/src/wizard/PageNetwork.cpp

80 lines
2.5 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2022-02-10 10:26:41 +00:00
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
2021-03-12 18:26:48 +00:00
#include "PageNetwork.h"
#include "ui_PageNetwork.h"
2021-07-04 03:40:31 +00:00
#include <QtConcurrent/QtConcurrent>
2021-05-18 15:59:18 +00:00
#include "constants.h"
2021-07-06 19:36:27 +00:00
#include "Utils.h"
2021-07-04 03:40:31 +00:00
#include "WalletWizard.h"
2021-05-18 15:59:18 +00:00
PageNetwork::PageNetwork(QWidget *parent)
2021-05-02 18:22:38 +00:00
: QWizardPage(parent)
, ui(new Ui::PageNetwork)
2021-07-04 03:40:31 +00:00
, m_portOpenWatcher(new QFutureWatcher<QPair<bool, QString>>(this))
2021-05-02 18:22:38 +00:00
{
ui->setupUi(this);
2021-05-02 18:22:38 +00:00
this->setTitle("Welcome to Feather");
2021-07-04 03:40:31 +00:00
ui->frame_nodeDetected->hide();
2021-05-02 18:22:38 +00:00
ui->frame_customNode->hide();
2021-07-04 03:40:31 +00:00
ui->btnGroup_network->setId(ui->radio_autoConnect, Button::AUTO);
ui->btnGroup_network->setId(ui->radio_custom, Button::CUSTOM);
QPixmap infoIcon = QPixmap(":/assets/images/info2.svg");
ui->infoIcon->setPixmap(infoIcon.scaledToWidth(32, Qt::SmoothTransformation));
2021-05-02 18:22:38 +00:00
connect(ui->btnGroup_network, &QButtonGroup::idClicked, [this](int id) {
2021-07-04 03:40:31 +00:00
ui->frame_customNode->setVisible(id == Button::CUSTOM);
2021-05-02 18:22:38 +00:00
});
connect(ui->line_customNode, &QLineEdit::textEdited, [this]{
this->completeChanged();
});
2021-07-04 03:40:31 +00:00
connect(m_portOpenWatcher, &QFutureWatcher<QPair<bool, QString>>::finished, [this](){
auto res = m_portOpenWatcher->result();
bool nodeFound = res.first;
if (nodeFound) {
ui->frame_nodeDetected->show();
ui->label_nodeDetected->setText(QString("Feather detected a local node on %1").arg(res.second));
ui->btnGroup_network->button(Button::CUSTOM)->click();
ui->line_customNode->setText(res.second);
}
});
QFuture<QPair<bool, QString>> portOpen = QtConcurrent::run([]{
QString localhost = "127.0.0.1";
quint16 port = Utils::getDefaultRpcPort(constants::networkType);
return QPair<bool, QString>{Utils::portOpen(localhost, port), QString("%1:%2").arg(localhost, QString::number(port))};
});
m_portOpenWatcher->setFuture(portOpen);
}
2021-03-12 18:26:48 +00:00
int PageNetwork::nextId() const {
2021-05-02 18:22:38 +00:00
return WalletWizard::Page_NetworkTor;
}
2021-03-12 18:26:48 +00:00
bool PageNetwork::validatePage() {
2021-05-02 18:22:38 +00:00
int id = ui->btnGroup_network->checkedId();
config()->set(Config::nodeSource, id);
2021-07-04 03:40:31 +00:00
if (id == Button::CUSTOM) {
2021-05-18 15:59:18 +00:00
NodeList nodeList;
nodeList.addNode(ui->line_customNode->text(), constants::networkType, NodeList::Type::custom);
}
2021-05-02 18:22:38 +00:00
return true;
2021-05-02 18:22:38 +00:00
}
bool PageNetwork::isComplete() const {
2021-07-04 03:40:31 +00:00
if (ui->btnGroup_network->checkedId() == Button::AUTO) {
2021-05-02 18:22:38 +00:00
return true;
}
FeatherNode node{ui->line_customNode->text()};
return node.isValid();
}