2017-03-14 12:34:01 +00:00
|
|
|
#include "TunnelPane.h"
|
2017-09-08 10:58:04 +00:00
|
|
|
|
2017-06-02 14:59:13 +00:00
|
|
|
#include "QMessageBox"
|
2017-09-08 10:58:04 +00:00
|
|
|
#include "mainwindow.h"
|
2017-09-08 11:42:25 +00:00
|
|
|
#include "ui_mainwindow.h"
|
2017-03-14 12:34:01 +00:00
|
|
|
|
2017-09-08 10:58:04 +00:00
|
|
|
TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_):
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject(),
|
2017-09-08 10:58:04 +00:00
|
|
|
mainWindow(mainWindow_),
|
2017-09-08 09:57:15 +00:00
|
|
|
wrongInputPane(wrongInputPane_),
|
|
|
|
wrongInputLabel(wrongInputLabel_),
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelConfig(tunnelConfig_),
|
|
|
|
tunnelsPageUpdateListener(tunnelsPageUpdateListener_),
|
|
|
|
gridLayoutWidget_2(nullptr) {}
|
2017-03-14 12:34:01 +00:00
|
|
|
|
|
|
|
void TunnelPane::setupTunnelPane(
|
|
|
|
TunnelConfig* tunnelConfig,
|
|
|
|
QGroupBox *tunnelGroupBox,
|
|
|
|
QWidget* gridLayoutWidget_2, QComboBox * tunnelTypeComboBox,
|
2017-06-02 14:59:13 +00:00
|
|
|
QWidget *tunnelsFormGridLayoutWidget, int tunnelsRow, int height, int h) {
|
|
|
|
tunnelGroupBox->setGeometry(0, tunnelsFormGridLayoutWidget->height(), gridLayoutWidget_2->width(), h);
|
|
|
|
tunnelsFormGridLayoutWidget->resize(527, tunnelsFormGridLayoutWidget->height()+h);
|
|
|
|
|
|
|
|
QObject::connect(tunnelTypeComboBox, SIGNAL(currentIndexChanged(int)),
|
|
|
|
this, SLOT(updated()));
|
2017-04-02 19:39:24 +00:00
|
|
|
|
|
|
|
|
2017-03-14 12:34:01 +00:00
|
|
|
this->tunnelGroupBox=tunnelGroupBox;
|
2017-04-02 19:39:24 +00:00
|
|
|
|
2017-03-14 12:34:01 +00:00
|
|
|
gridLayoutWidget_2->setObjectName(QStringLiteral("gridLayoutWidget_2"));
|
|
|
|
this->gridLayoutWidget_2=gridLayoutWidget_2;
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout = new QVBoxLayout(gridLayoutWidget_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
tunnelGridLayout->setObjectName(QStringLiteral("tunnelGridLayout"));
|
|
|
|
tunnelGridLayout->setContentsMargins(5, 5, 5, 5);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->setSpacing(5);
|
2017-03-14 12:34:01 +00:00
|
|
|
|
|
|
|
//header
|
|
|
|
QHBoxLayout *headerHorizontalLayout = new QHBoxLayout();
|
|
|
|
headerHorizontalLayout->setObjectName(QStringLiteral("headerHorizontalLayout"));
|
|
|
|
|
|
|
|
nameLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
nameLabel->setObjectName(QStringLiteral("nameLabel"));
|
|
|
|
headerHorizontalLayout->addWidget(nameLabel);
|
|
|
|
nameLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
nameLineEdit->setObjectName(QStringLiteral("nameLineEdit"));
|
|
|
|
const QString& tunnelName=tunnelConfig->getName().c_str();
|
|
|
|
nameLineEdit->setText(tunnelName);
|
|
|
|
setGroupBoxTitle(tunnelName);
|
|
|
|
|
|
|
|
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(setGroupBoxTitle(const QString &)));
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
|
|
|
|
headerHorizontalLayout->addWidget(nameLineEdit);
|
|
|
|
headerHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
headerHorizontalLayout->addItem(headerHorizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
deletePushButton = new QPushButton(gridLayoutWidget_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
deletePushButton->setObjectName(QStringLiteral("deletePushButton"));
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(deletePushButton, SIGNAL(released()),
|
|
|
|
this, SLOT(deleteButtonReleased()));//MainWindow::DeleteTunnelNamed(std::string name) {
|
2017-03-14 12:34:01 +00:00
|
|
|
headerHorizontalLayout->addWidget(deletePushButton);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(headerHorizontalLayout);
|
2017-03-14 12:34:01 +00:00
|
|
|
|
|
|
|
//type
|
|
|
|
{
|
|
|
|
const QString& type = tunnelConfig->getType();
|
|
|
|
QHBoxLayout * horizontalLayout_ = new QHBoxLayout();
|
|
|
|
horizontalLayout_->setObjectName(QStringLiteral("horizontalLayout_"));
|
|
|
|
typeLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
typeLabel->setObjectName(QStringLiteral("typeLabel"));
|
|
|
|
horizontalLayout_->addWidget(typeLabel);
|
|
|
|
horizontalLayout_->addWidget(tunnelTypeComboBox);
|
2017-08-27 08:10:09 +00:00
|
|
|
QPushButton * lockButton1 = new QPushButton(gridLayoutWidget_2);
|
|
|
|
horizontalLayout_->addWidget(lockButton1);
|
|
|
|
widgetlocks.add(new widgetlock(tunnelTypeComboBox, lockButton1));
|
2017-03-14 12:34:01 +00:00
|
|
|
this->tunnelTypeComboBox=tunnelTypeComboBox;
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retranslateTunnelForm(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters, int& gridIndex) {
|
|
|
|
{
|
|
|
|
//number of hops of an inbound tunnel
|
|
|
|
const QString& inbound_length=i2cpParameters.getInbound_length();
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
|
|
|
|
inbound_lengthLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
inbound_lengthLabel->setObjectName(QStringLiteral("inbound_lengthLabel"));
|
|
|
|
horizontalLayout_2->addWidget(inbound_lengthLabel);
|
|
|
|
inbound_lengthLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
inbound_lengthLineEdit->setObjectName(QStringLiteral("inbound_lengthLineEdit"));
|
|
|
|
inbound_lengthLineEdit->setText(inbound_length);
|
|
|
|
inbound_lengthLineEdit->setMaximumWidth(80);
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(inbound_lengthLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
horizontalLayout_2->addWidget(inbound_lengthLineEdit);
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_2->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
//number of hops of an outbound tunnel
|
|
|
|
const QString& outbound_length=i2cpParameters.getOutbound_length();
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
|
|
|
|
outbound_lengthLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
outbound_lengthLabel->setObjectName(QStringLiteral("outbound_lengthLabel"));
|
|
|
|
horizontalLayout_2->addWidget(outbound_lengthLabel);
|
|
|
|
outbound_lengthLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
outbound_lengthLineEdit->setObjectName(QStringLiteral("outbound_lengthLineEdit"));
|
|
|
|
outbound_lengthLineEdit->setText(outbound_length);
|
|
|
|
outbound_lengthLineEdit->setMaximumWidth(80);
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(outbound_lengthLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
horizontalLayout_2->addWidget(outbound_lengthLineEdit);
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_2->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
//number of inbound tunnels
|
|
|
|
const QString& inbound_quantity=i2cpParameters.getInbound_quantity();
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
|
|
|
|
inbound_quantityLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
inbound_quantityLabel->setObjectName(QStringLiteral("inbound_quantityLabel"));
|
|
|
|
horizontalLayout_2->addWidget(inbound_quantityLabel);
|
|
|
|
inbound_quantityLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
inbound_quantityLineEdit->setObjectName(QStringLiteral("inbound_quantityLineEdit"));
|
|
|
|
inbound_quantityLineEdit->setText(inbound_quantity);
|
|
|
|
inbound_quantityLineEdit->setMaximumWidth(80);
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(inbound_quantityLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
horizontalLayout_2->addWidget(inbound_quantityLineEdit);
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_2->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
//number of outbound tunnels
|
|
|
|
const QString& outbound_quantity=i2cpParameters.getOutbound_quantity();
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
|
|
|
|
outbound_quantityLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
outbound_quantityLabel->setObjectName(QStringLiteral("outbound_quantityLabel"));
|
|
|
|
horizontalLayout_2->addWidget(outbound_quantityLabel);
|
|
|
|
outbound_quantityLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
outbound_quantityLineEdit->setObjectName(QStringLiteral("outbound_quantityLineEdit"));
|
|
|
|
outbound_quantityLineEdit->setText(outbound_quantity);
|
|
|
|
outbound_quantityLineEdit->setMaximumWidth(80);
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(outbound_quantityLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
horizontalLayout_2->addWidget(outbound_quantityLineEdit);
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_2->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
//number of ElGamal/AES tags to send
|
|
|
|
const QString& crypto_tagsToSend=i2cpParameters.getCrypto_tagsToSend();
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
|
|
|
|
crypto_tagsToSendLabel = new QLabel(gridLayoutWidget_2);
|
|
|
|
crypto_tagsToSendLabel->setObjectName(QStringLiteral("crypto_tagsToSendLabel"));
|
|
|
|
horizontalLayout_2->addWidget(crypto_tagsToSendLabel);
|
|
|
|
crypto_tagsToSendLineEdit = new QLineEdit(gridLayoutWidget_2);
|
|
|
|
crypto_tagsToSendLineEdit->setObjectName(QStringLiteral("crypto_tagsToSendLineEdit"));
|
|
|
|
crypto_tagsToSendLineEdit->setText(crypto_tagsToSend);
|
|
|
|
crypto_tagsToSendLineEdit->setMaximumWidth(80);
|
2017-06-02 14:59:13 +00:00
|
|
|
QObject::connect(crypto_tagsToSendLineEdit, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updated()));
|
2017-03-14 12:34:01 +00:00
|
|
|
horizontalLayout_2->addWidget(crypto_tagsToSendLineEdit);
|
|
|
|
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
horizontalLayout_2->addItem(horizontalSpacer);
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelGridLayout->addLayout(horizontalLayout_2);
|
2017-03-14 12:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retranslateI2CPParameters();
|
|
|
|
}
|
2017-06-02 14:59:13 +00:00
|
|
|
|
|
|
|
void TunnelPane::updated() {
|
|
|
|
std::string oldName=tunnelConfig->getName();
|
2017-09-08 11:42:25 +00:00
|
|
|
//validate and show red if invalid
|
2017-09-08 17:09:31 +00:00
|
|
|
hideWrongInputLabel();
|
2017-09-08 15:25:25 +00:00
|
|
|
if(!mainWindow->applyTunnelsUiToConfigs())return;
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelsPageUpdateListener->updated(oldName, tunnelConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TunnelPane::deleteButtonReleased() {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(QApplication::tr("Are you sure to delete this tunnel?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
int ret = msgBox.exec();
|
|
|
|
switch (ret) {
|
|
|
|
case QMessageBox::Ok:
|
|
|
|
// OK was clicked
|
2017-09-08 17:13:42 +00:00
|
|
|
hideWrongInputLabel();
|
2017-06-02 14:59:13 +00:00
|
|
|
tunnelsPageUpdateListener->needsDeleting(tunnelConfig->getName());
|
|
|
|
break;
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
// Cancel was clicked
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_CLIENT[] = "client";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_SERVER[] = "server";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_HTTP[] = "http";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_IRC[] = "irc";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_UDPCLIENT[] = "udpclient";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_UDPSERVER[] = "udpserver";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_SOCKS[] = "socks";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_WEBSOCKS[] = "websocks";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_HTTPPROXY[] = "httpproxy";
|
|
|
|
*/
|
|
|
|
QString TunnelPane::readTunnelTypeComboboxData() {
|
|
|
|
return tunnelTypeComboBox->currentData().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
i2p::data::SigningKeyType TunnelPane::readSigTypeComboboxUI(QComboBox* sigTypeComboBox) {
|
|
|
|
return (i2p::data::SigningKeyType) sigTypeComboBox->currentData().toInt();
|
|
|
|
}
|
2017-09-08 07:59:19 +00:00
|
|
|
|
|
|
|
void TunnelPane::deleteTunnelForm() {
|
|
|
|
widgetlocks.deleteListeners();
|
|
|
|
}
|
2017-09-08 10:58:04 +00:00
|
|
|
|
|
|
|
void TunnelPane::highlightWrongInput(QString warningText, QWidget* controlWithWrongInput) {
|
|
|
|
wrongInputPane->setVisible(true);
|
|
|
|
wrongInputLabel->setText(warningText);
|
2017-09-08 17:13:42 +00:00
|
|
|
mainWindow->adjustSizesAccordingToWrongLabel();
|
2017-09-08 11:42:25 +00:00
|
|
|
if(controlWithWrongInput){
|
|
|
|
mainWindow->ui->tunnelsScrollArea->ensureWidgetVisible(controlWithWrongInput);
|
|
|
|
controlWithWrongInput->setFocus();
|
|
|
|
}
|
2017-09-08 10:58:04 +00:00
|
|
|
mainWindow->showTunnelsPage();
|
|
|
|
}
|
2017-09-08 15:07:27 +00:00
|
|
|
|
|
|
|
void TunnelPane::hideWrongInputLabel() const {
|
|
|
|
wrongInputPane->setVisible(false);
|
2017-09-08 17:13:42 +00:00
|
|
|
mainWindow->adjustSizesAccordingToWrongLabel();
|
2017-09-08 15:07:27 +00:00
|
|
|
}
|