mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-08 08:51:00 +00:00
Changed some structure of classes Handler and MainWindow. Also added the line "My IP" on the main window.
This commit is contained in:
parent
8d8649e5f9
commit
f694a32f3e
@ -2,6 +2,11 @@
|
||||
|
||||
Handler::Handler()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
|
||||
handlers = {
|
||||
{"createSession", std::bind(&Handler::createSession, this, _1)}
|
||||
};
|
||||
network = new Network();
|
||||
connect(network, &Network::json_received, this, &Handler::handle);
|
||||
}
|
||||
@ -9,11 +14,6 @@ Handler::Handler()
|
||||
|
||||
void Handler::handle(QJsonObject jsonReceived)
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
std::map<QString, std::function<void(QJsonObject)>> handlers = {
|
||||
{"createSession", std::bind(&Handler::createSession, this, _1)}
|
||||
};
|
||||
|
||||
QString action = jsonReceived["action"].toString();
|
||||
handlers[action](jsonReceived);
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ class Handler : public QObject
|
||||
private:
|
||||
Network *network;
|
||||
void createSession(QJsonObject jsonReceived);
|
||||
std::map<QString, std::function<void(QJsonObject)>> handlers;
|
||||
private slots:
|
||||
void handle(QJsonObject jsonReceived);
|
||||
|
||||
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ QString Network::local_ipv6()
|
||||
{
|
||||
QHostAddress address;
|
||||
foreach (address, QNetworkInterface::allAddresses()) {
|
||||
if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHostIPv6))
|
||||
if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHostIPv6) && (address.toString()).contains("fc"))
|
||||
break;
|
||||
}
|
||||
return(address.toString());
|
||||
|
@ -8,7 +8,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
network = new Network(false);
|
||||
handler = new Handler();
|
||||
timer = new QTimer();
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));
|
||||
connect(handler, &Handler::createSessionSuccess, this, &MainWindow::peerReceiverConnected);
|
||||
ui->myIP->setText(my_ipv6);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -25,8 +28,6 @@ void MainWindow::on_connectToPeer_clicked()
|
||||
j["action"] = "createSession";
|
||||
QString s = ui->peerID->text();
|
||||
network->sendDatagram(j, s);
|
||||
timer = new QTimer();
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));
|
||||
timer->start(10000);
|
||||
}
|
||||
|
||||
@ -41,7 +42,6 @@ void MainWindow::slotTimerAlarm()
|
||||
{
|
||||
int ret = QMessageBox::critical(this,QObject::tr("Error"),tr("Timeout Error"));
|
||||
timer->stop();
|
||||
delete timer;
|
||||
ui->connectToPeer->setEnabled(true);
|
||||
ui->connectToPeer->setText("Подключиться");
|
||||
}
|
||||
|
@ -29,21 +29,35 @@
|
||||
<string>Influence</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QLineEdit" name="peerID">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Мой IP:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QPushButton" name="connectToPeer">
|
||||
<property name="text">
|
||||
<string>Подключиться</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="myIP">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
Loading…
Reference in New Issue
Block a user