Browse Source

qtui first draft completed

pull/892/head
hypnosis-i2p 8 years ago
parent
commit
298181999d
  1. 64
      qt/i2pd_qt/ClientTunnelPane.cpp
  2. 34
      qt/i2pd_qt/ClientTunnelPane.h
  3. 88
      qt/i2pd_qt/ServerTunnelPane.cpp
  4. 53
      qt/i2pd_qt/ServerTunnelPane.h
  5. 2
      qt/i2pd_qt/SignatureTypeComboboxFactory.h
  6. 39
      qt/i2pd_qt/TunnelConfig.cpp
  7. 27
      qt/i2pd_qt/TunnelConfig.h
  8. 94
      qt/i2pd_qt/TunnelPane.cpp
  9. 34
      qt/i2pd_qt/TunnelPane.h
  10. 12
      qt/i2pd_qt/TunnelsPageUpdateListener.h
  11. 107
      qt/i2pd_qt/mainwindow.cpp
  12. 137
      qt/i2pd_qt/mainwindow.h
  13. 54
      qt/i2pd_qt/mainwindow.ui

64
qt/i2pd_qt/ClientTunnelPane.cpp

@ -1,28 +1,25 @@
#include "ClientTunnelPane.h" #include "ClientTunnelPane.h"
#include "../../ClientContext.h" #include "../../ClientContext.h"
#include "SignatureTypeComboboxFactory.h" #include "SignatureTypeComboboxFactory.h"
#include "QVBoxLayout"
ClientTunnelPane::ClientTunnelPane() ClientTunnelPane::ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf):
{ TunnelPane(tunnelsPageUpdateListener, tunconf) {}
}
void ClientTunnelPane::setGroupBoxTitle(const QString & title) { void ClientTunnelPane::setGroupBoxTitle(const QString & title) {
clientTunnelNameGroupBox->setTitle(title); clientTunnelNameGroupBox->setTitle(title);
} }
void ClientTunnelPane::deleteClientTunnelForm(QGridLayout *tunnelsFormGridLayout) { void ClientTunnelPane::deleteClientTunnelForm() {
tunnelsFormGridLayout->removeWidget(clientTunnelNameGroupBox); delete clientTunnelNameGroupBox;
clientTunnelNameGroupBox->deleteLater();
clientTunnelNameGroupBox=nullptr; clientTunnelNameGroupBox=nullptr;
gridLayoutWidget_2->deleteLater(); //gridLayoutWidget_2->deleteLater();
gridLayoutWidget_2=nullptr; //gridLayoutWidget_2=nullptr;
} }
void ClientTunnelPane::appendClientTunnelForm( int ClientTunnelPane::appendClientTunnelForm(
ClientTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, QGridLayout *tunnelsFormGridLayout, int tunnelsRow) { ClientTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, int tunnelsRow, int height) {
ClientTunnelPane& ui = *this; ClientTunnelPane& ui = *this;
@ -30,7 +27,7 @@ void ClientTunnelPane::appendClientTunnelForm(
clientTunnelNameGroupBox->setObjectName(QStringLiteral("clientTunnelNameGroupBox")); clientTunnelNameGroupBox->setObjectName(QStringLiteral("clientTunnelNameGroupBox"));
//tunnel //tunnel
ui.gridLayoutWidget_2 = new QWidget(clientTunnelNameGroupBox); gridLayoutWidget_2 = new QWidget(clientTunnelNameGroupBox);
QComboBox *tunnelTypeComboBox = new QComboBox(gridLayoutWidget_2); QComboBox *tunnelTypeComboBox = new QComboBox(gridLayoutWidget_2);
tunnelTypeComboBox->setObjectName(QStringLiteral("tunnelTypeComboBox")); tunnelTypeComboBox->setObjectName(QStringLiteral("tunnelTypeComboBox"));
@ -40,13 +37,10 @@ void ClientTunnelPane::appendClientTunnelForm(
tunnelTypeComboBox->addItem("HTTP Proxy", i2p::client::I2P_TUNNELS_SECTION_TYPE_HTTPPROXY); tunnelTypeComboBox->addItem("HTTP Proxy", i2p::client::I2P_TUNNELS_SECTION_TYPE_HTTPPROXY);
tunnelTypeComboBox->addItem("UDP Client", i2p::client::I2P_TUNNELS_SECTION_TYPE_UDPCLIENT); tunnelTypeComboBox->addItem("UDP Client", i2p::client::I2P_TUNNELS_SECTION_TYPE_UDPCLIENT);
gridLayoutWidget_2->setGeometry(QRect(0, 0, 561, (7+4)*60)); int h=(7+4)*60;
gridLayoutWidget_2->setGeometry(QRect(0, 0, 561, h));
clientTunnelNameGroupBox->setGeometry(QRect(0, 0, 561, h));
setupTunnelPane(tunnelConfig,
clientTunnelNameGroupBox,
gridLayoutWidget_2, tunnelTypeComboBox,
tunnelsFormGridLayoutWidget, tunnelsFormGridLayout, tunnelsRow);
//this->tunnelGroupBox->setGeometry(QRect(0, tunnelsFormGridLayoutWidget->height()+10, 561, (7+5)*40+10));
{ {
const QString& type = tunnelConfig->getType(); const QString& type = tunnelConfig->getType();
int index=0; int index=0;
@ -62,6 +56,12 @@ void ClientTunnelPane::appendClientTunnelForm(
++index; ++index;
} }
setupTunnelPane(tunnelConfig,
clientTunnelNameGroupBox,
gridLayoutWidget_2, tunnelTypeComboBox,
tunnelsFormGridLayoutWidget, tunnelsRow, height, h);
//this->tunnelGroupBox->setGeometry(QRect(0, tunnelsFormGridLayoutWidget->height()+10, 561, (7+5)*40+10));
/* /*
std::string destination; std::string destination;
*/ */
@ -75,10 +75,12 @@ void ClientTunnelPane::appendClientTunnelForm(
ui.destinationLineEdit = new QLineEdit(gridLayoutWidget_2); ui.destinationLineEdit = new QLineEdit(gridLayoutWidget_2);
destinationLineEdit->setObjectName(QStringLiteral("destinationLineEdit")); destinationLineEdit->setObjectName(QStringLiteral("destinationLineEdit"));
destinationLineEdit->setText(tunnelConfig->getdest().c_str()); destinationLineEdit->setText(tunnelConfig->getdest().c_str());
QObject::connect(destinationLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(destinationLineEdit); horizontalLayout_2->addWidget(destinationLineEdit);
ui.destinationHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); ui.destinationHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(destinationHorizontalSpacer); horizontalLayout_2->addItem(destinationHorizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, 2, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
/* /*
* int port; * int port;
@ -95,10 +97,12 @@ void ClientTunnelPane::appendClientTunnelForm(
portLineEdit->setObjectName(QStringLiteral("portLineEdit")); portLineEdit->setObjectName(QStringLiteral("portLineEdit"));
portLineEdit->setText(QString::number(port)); portLineEdit->setText(QString::number(port));
portLineEdit->setMaximumWidth(80); portLineEdit->setMaximumWidth(80);
QObject::connect(portLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(portLineEdit); horizontalLayout_2->addWidget(portLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
/* /*
* std::string keys; * std::string keys;
@ -113,10 +117,12 @@ void ClientTunnelPane::appendClientTunnelForm(
ui.keysLineEdit = new QLineEdit(gridLayoutWidget_2); ui.keysLineEdit = new QLineEdit(gridLayoutWidget_2);
keysLineEdit->setObjectName(QStringLiteral("keysLineEdit")); keysLineEdit->setObjectName(QStringLiteral("keysLineEdit"));
keysLineEdit->setText(keys.c_str()); keysLineEdit->setText(keys.c_str());
QObject::connect(keysLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(keysLineEdit); horizontalLayout_2->addWidget(keysLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
/* /*
* std::string address; * std::string address;
@ -131,10 +137,12 @@ void ClientTunnelPane::appendClientTunnelForm(
ui.addressLineEdit = new QLineEdit(gridLayoutWidget_2); ui.addressLineEdit = new QLineEdit(gridLayoutWidget_2);
addressLineEdit->setObjectName(QStringLiteral("addressLineEdit")); addressLineEdit->setObjectName(QStringLiteral("addressLineEdit"));
addressLineEdit->setText(address.c_str()); addressLineEdit->setText(address.c_str());
QObject::connect(addressLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(addressLineEdit); horizontalLayout_2->addWidget(addressLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
/* /*
@ -152,10 +160,12 @@ void ClientTunnelPane::appendClientTunnelForm(
destinationPortLineEdit->setObjectName(QStringLiteral("destinationPortLineEdit")); destinationPortLineEdit->setObjectName(QStringLiteral("destinationPortLineEdit"));
destinationPortLineEdit->setText(QString::number(destinationPort)); destinationPortLineEdit->setText(QString::number(destinationPort));
destinationPortLineEdit->setMaximumWidth(80); destinationPortLineEdit->setMaximumWidth(80);
QObject::connect(destinationPortLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(destinationPortLineEdit); horizontalLayout_2->addWidget(destinationPortLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
i2p::data::SigningKeyType sigType = tunnelConfig->getsigType(); i2p::data::SigningKeyType sigType = tunnelConfig->getsigType();
@ -166,10 +176,12 @@ void ClientTunnelPane::appendClientTunnelForm(
horizontalLayout_2->addWidget(sigTypeLabel); horizontalLayout_2->addWidget(sigTypeLabel);
ui.sigTypeComboBox = SignatureTypeComboBoxFactory::createSignatureTypeComboBox(gridLayoutWidget_2, sigType); ui.sigTypeComboBox = SignatureTypeComboBoxFactory::createSignatureTypeComboBox(gridLayoutWidget_2, sigType);
sigTypeComboBox->setObjectName(QStringLiteral("sigTypeComboBox")); sigTypeComboBox->setObjectName(QStringLiteral("sigTypeComboBox"));
QObject::connect(sigTypeComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(sigTypeComboBox); horizontalLayout_2->addWidget(sigTypeComboBox);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
I2CPParameters& i2cpParameters = tunnelConfig->getI2cpParameters(); I2CPParameters& i2cpParameters = tunnelConfig->getI2cpParameters();
@ -179,6 +191,8 @@ void ClientTunnelPane::appendClientTunnelForm(
retranslateClientTunnelForm(ui); retranslateClientTunnelForm(ui);
tunnelGridLayout->invalidate(); tunnelGridLayout->invalidate();
return h;
} }
ServerTunnelPane* ClientTunnelPane::asServerTunnelPane(){return nullptr;} ServerTunnelPane* ClientTunnelPane::asServerTunnelPane(){return nullptr;}

34
qt/i2pd_qt/ClientTunnelPane.h

@ -2,6 +2,7 @@
#define CLIENTTUNNELPANE_H #define CLIENTTUNNELPANE_H
#include "QGridLayout" #include "QGridLayout"
#include "QVBoxLayout"
#include "TunnelPane.h" #include "TunnelPane.h"
@ -13,13 +14,13 @@ class TunnelPane;
class ClientTunnelPane : public TunnelPane { class ClientTunnelPane : public TunnelPane {
Q_OBJECT Q_OBJECT
public: public:
ClientTunnelPane(); ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf);
virtual ~ClientTunnelPane(){} virtual ~ClientTunnelPane(){}
virtual ServerTunnelPane* asServerTunnelPane(); virtual ServerTunnelPane* asServerTunnelPane();
virtual ClientTunnelPane* asClientTunnelPane(); virtual ClientTunnelPane* asClientTunnelPane();
void appendClientTunnelForm(ClientTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, int appendClientTunnelForm(ClientTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget,
QGridLayout *tunnelsFormGridLayout, int tunnelsRow); int tunnelsRow, int height);
void deleteClientTunnelForm(QGridLayout *tunnelsFormGridLayout); void deleteClientTunnelForm();
private: private:
QGroupBox *clientTunnelNameGroupBox; QGroupBox *clientTunnelNameGroupBox;
@ -65,7 +66,32 @@ private:
addressLabel->setText(QApplication::translate("cltTunForm", "Address:", 0)); addressLabel->setText(QApplication::translate("cltTunForm", "Address:", 0));
sigTypeLabel->setText(QApplication::translate("cltTunForm", "Signature type:", 0)); sigTypeLabel->setText(QApplication::translate("cltTunForm", "Signature type:", 0));
} }
protected:
virtual bool applyDataFromUIToTunnelConfig() {
bool ok=TunnelPane::applyDataFromUIToTunnelConfig();
if(!ok)return false;
ClientTunnelConfig* ctc=tunnelConfig->asClientTunnelConfig();
assert(ctc!=nullptr);
//destination
ctc->setdest(destinationLineEdit->text().toStdString());
auto portStr=portLineEdit->text();
int portInt=portStr.toInt(&ok);
if(!ok)return false;
ctc->setport(portInt);
ctc->setkeys(keysLineEdit->text().toStdString());
ctc->setaddress(addressLineEdit->text().toStdString());
auto dportStr=portLineEdit->text();
int dportInt=dportStr.toInt(&ok);
if(!ok)return false;
ctc->setdestinationPort(dportInt);
ctc->setsigType(readSigTypeComboboxUI(sigTypeComboBox));
}
}; };
#endif // CLIENTTUNNELPANE_H #endif // CLIENTTUNNELPANE_H

88
qt/i2pd_qt/ServerTunnelPane.cpp

@ -2,14 +2,15 @@
#include "../../ClientContext.h" #include "../../ClientContext.h"
#include "SignatureTypeComboboxFactory.h" #include "SignatureTypeComboboxFactory.h"
ServerTunnelPane::ServerTunnelPane(): TunnelPane() {} ServerTunnelPane::ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf):
TunnelPane(tunnelsPageUpdateListener, tunconf) {}
void ServerTunnelPane::setGroupBoxTitle(const QString & title) { void ServerTunnelPane::setGroupBoxTitle(const QString & title) {
serverTunnelNameGroupBox->setTitle(title); serverTunnelNameGroupBox->setTitle(title);
} }
void ServerTunnelPane::appendServerTunnelForm( int ServerTunnelPane::appendServerTunnelForm(
ServerTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, QGridLayout *tunnelsFormGridLayout, int tunnelsRow) { ServerTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, int tunnelsRow, int height) {
ServerTunnelPane& ui = *this; ServerTunnelPane& ui = *this;
@ -17,7 +18,7 @@ void ServerTunnelPane::appendServerTunnelForm(
serverTunnelNameGroupBox->setObjectName(QStringLiteral("serverTunnelNameGroupBox")); serverTunnelNameGroupBox->setObjectName(QStringLiteral("serverTunnelNameGroupBox"));
//tunnel //tunnel
ui.gridLayoutWidget_2 = new QWidget(serverTunnelNameGroupBox); gridLayoutWidget_2 = new QWidget(serverTunnelNameGroupBox);
QComboBox *tunnelTypeComboBox = new QComboBox(gridLayoutWidget_2); QComboBox *tunnelTypeComboBox = new QComboBox(gridLayoutWidget_2);
tunnelTypeComboBox->setObjectName(QStringLiteral("tunnelTypeComboBox")); tunnelTypeComboBox->setObjectName(QStringLiteral("tunnelTypeComboBox"));
@ -26,14 +27,9 @@ void ServerTunnelPane::appendServerTunnelForm(
tunnelTypeComboBox->addItem("IRC", i2p::client::I2P_TUNNELS_SECTION_TYPE_IRC); tunnelTypeComboBox->addItem("IRC", i2p::client::I2P_TUNNELS_SECTION_TYPE_IRC);
tunnelTypeComboBox->addItem("UDP Server", i2p::client::I2P_TUNNELS_SECTION_TYPE_UDPSERVER); tunnelTypeComboBox->addItem("UDP Server", i2p::client::I2P_TUNNELS_SECTION_TYPE_UDPSERVER);
gridLayoutWidget_2->setGeometry(QRect(0, 0, 561, 18*60)); int h=19*60;
gridLayoutWidget_2->setGeometry(QRect(0, 0, 561, h));
serverTunnelNameGroupBox->setGeometry(QRect(0, 0, 561, h));
setupTunnelPane(tunnelConfig,
serverTunnelNameGroupBox,
gridLayoutWidget_2, tunnelTypeComboBox,
tunnelsFormGridLayoutWidget, tunnelsFormGridLayout, tunnelsRow);
//this->tunnelGroupBox->setGeometry(QRect(0, tunnelsFormGridLayoutWidget->height()+10, 561, 18*40+10));
{ {
const QString& type = tunnelConfig->getType(); const QString& type = tunnelConfig->getType();
@ -48,6 +44,12 @@ void ServerTunnelPane::appendServerTunnelForm(
++index; ++index;
} }
setupTunnelPane(tunnelConfig,
serverTunnelNameGroupBox,
gridLayoutWidget_2, tunnelTypeComboBox,
tunnelsFormGridLayoutWidget, tunnelsRow, height, h);
//this->tunnelGroupBox->setGeometry(QRect(0, tunnelsFormGridLayoutWidget->height()+10, 561, 18*40+10));
//host //host
ui.horizontalLayout_2 = new QHBoxLayout(); ui.horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2")); horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
@ -57,10 +59,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.hostLineEdit = new QLineEdit(gridLayoutWidget_2); ui.hostLineEdit = new QLineEdit(gridLayoutWidget_2);
hostLineEdit->setObjectName(QStringLiteral("hostLineEdit")); hostLineEdit->setObjectName(QStringLiteral("hostLineEdit"));
hostLineEdit->setText(tunnelConfig->gethost().c_str()); hostLineEdit->setText(tunnelConfig->gethost().c_str());
QObject::connect(hostLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(hostLineEdit); horizontalLayout_2->addWidget(hostLineEdit);
ui.hostHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); ui.hostHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(hostHorizontalSpacer); horizontalLayout_2->addItem(hostHorizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, 2, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
int gridIndex = 2; int gridIndex = 2;
{ {
@ -74,10 +78,12 @@ void ServerTunnelPane::appendServerTunnelForm(
portLineEdit->setObjectName(QStringLiteral("portLineEdit")); portLineEdit->setObjectName(QStringLiteral("portLineEdit"));
portLineEdit->setText(QString::number(port)); portLineEdit->setText(QString::number(port));
portLineEdit->setMaximumWidth(80); portLineEdit->setMaximumWidth(80);
QObject::connect(portLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(portLineEdit); horizontalLayout_2->addWidget(portLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
std::string keys = tunnelConfig->getkeys(); std::string keys = tunnelConfig->getkeys();
@ -89,10 +95,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.keysLineEdit = new QLineEdit(gridLayoutWidget_2); ui.keysLineEdit = new QLineEdit(gridLayoutWidget_2);
keysLineEdit->setObjectName(QStringLiteral("keysLineEdit")); keysLineEdit->setObjectName(QStringLiteral("keysLineEdit"));
keysLineEdit->setText(keys.c_str()); keysLineEdit->setText(keys.c_str());
QObject::connect(keysLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(keysLineEdit); horizontalLayout_2->addWidget(keysLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
int inPort = tunnelConfig->getinPort(); int inPort = tunnelConfig->getinPort();
@ -105,10 +113,12 @@ void ServerTunnelPane::appendServerTunnelForm(
inPortLineEdit->setObjectName(QStringLiteral("inPortLineEdit")); inPortLineEdit->setObjectName(QStringLiteral("inPortLineEdit"));
inPortLineEdit->setText(QString::number(inPort)); inPortLineEdit->setText(QString::number(inPort));
inPortLineEdit->setMaximumWidth(80); inPortLineEdit->setMaximumWidth(80);
QObject::connect(inPortLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(inPortLineEdit); horizontalLayout_2->addWidget(inPortLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
std::string accessList = tunnelConfig->getaccessList(); std::string accessList = tunnelConfig->getaccessList();
@ -120,10 +130,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.accessListLineEdit = new QLineEdit(gridLayoutWidget_2); ui.accessListLineEdit = new QLineEdit(gridLayoutWidget_2);
accessListLineEdit->setObjectName(QStringLiteral("accessListLineEdit")); accessListLineEdit->setObjectName(QStringLiteral("accessListLineEdit"));
accessListLineEdit->setText(accessList.c_str()); accessListLineEdit->setText(accessList.c_str());
QObject::connect(accessListLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(accessListLineEdit); horizontalLayout_2->addWidget(accessListLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
std::string hostOverride = tunnelConfig->gethostOverride(); std::string hostOverride = tunnelConfig->gethostOverride();
@ -135,10 +147,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.hostOverrideLineEdit = new QLineEdit(gridLayoutWidget_2); ui.hostOverrideLineEdit = new QLineEdit(gridLayoutWidget_2);
hostOverrideLineEdit->setObjectName(QStringLiteral("hostOverrideLineEdit")); hostOverrideLineEdit->setObjectName(QStringLiteral("hostOverrideLineEdit"));
hostOverrideLineEdit->setText(hostOverride.c_str()); hostOverrideLineEdit->setText(hostOverride.c_str());
QObject::connect(hostOverrideLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(hostOverrideLineEdit); horizontalLayout_2->addWidget(hostOverrideLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
std::string webIRCPass = tunnelConfig->getwebircpass(); std::string webIRCPass = tunnelConfig->getwebircpass();
@ -150,10 +164,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.webIRCPassLineEdit = new QLineEdit(gridLayoutWidget_2); ui.webIRCPassLineEdit = new QLineEdit(gridLayoutWidget_2);
webIRCPassLineEdit->setObjectName(QStringLiteral("webIRCPassLineEdit")); webIRCPassLineEdit->setObjectName(QStringLiteral("webIRCPassLineEdit"));
webIRCPassLineEdit->setText(webIRCPass.c_str()); webIRCPassLineEdit->setText(webIRCPass.c_str());
QObject::connect(webIRCPassLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(webIRCPassLineEdit); horizontalLayout_2->addWidget(webIRCPassLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
bool gzip = tunnelConfig->getgzip(); bool gzip = tunnelConfig->getgzip();
@ -162,10 +178,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.gzipCheckBox = new QCheckBox(gridLayoutWidget_2); ui.gzipCheckBox = new QCheckBox(gridLayoutWidget_2);
gzipCheckBox->setObjectName(QStringLiteral("gzipCheckBox")); gzipCheckBox->setObjectName(QStringLiteral("gzipCheckBox"));
gzipCheckBox->setChecked(gzip); gzipCheckBox->setChecked(gzip);
QObject::connect(gzipCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(gzipCheckBox); horizontalLayout_2->addWidget(gzipCheckBox);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
i2p::data::SigningKeyType sigType = tunnelConfig->getsigType(); i2p::data::SigningKeyType sigType = tunnelConfig->getsigType();
@ -176,10 +194,12 @@ void ServerTunnelPane::appendServerTunnelForm(
horizontalLayout_2->addWidget(sigTypeLabel); horizontalLayout_2->addWidget(sigTypeLabel);
ui.sigTypeComboBox = SignatureTypeComboBoxFactory::createSignatureTypeComboBox(gridLayoutWidget_2, sigType); ui.sigTypeComboBox = SignatureTypeComboBoxFactory::createSignatureTypeComboBox(gridLayoutWidget_2, sigType);
sigTypeComboBox->setObjectName(QStringLiteral("sigTypeComboBox")); sigTypeComboBox->setObjectName(QStringLiteral("sigTypeComboBox"));
QObject::connect(sigTypeComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(sigTypeComboBox); horizontalLayout_2->addWidget(sigTypeComboBox);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
uint32_t maxConns = tunnelConfig->getmaxConns(); uint32_t maxConns = tunnelConfig->getmaxConns();
@ -192,10 +212,12 @@ void ServerTunnelPane::appendServerTunnelForm(
maxConnsLineEdit->setObjectName(QStringLiteral("maxConnsLineEdit")); maxConnsLineEdit->setObjectName(QStringLiteral("maxConnsLineEdit"));
maxConnsLineEdit->setText(QString::number(maxConns)); maxConnsLineEdit->setText(QString::number(maxConns));
maxConnsLineEdit->setMaximumWidth(80); maxConnsLineEdit->setMaximumWidth(80);
QObject::connect(maxConnsLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(maxConnsLineEdit); horizontalLayout_2->addWidget(maxConnsLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
std::string address = tunnelConfig->getaddress(); std::string address = tunnelConfig->getaddress();
@ -207,10 +229,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.addressLineEdit = new QLineEdit(gridLayoutWidget_2); ui.addressLineEdit = new QLineEdit(gridLayoutWidget_2);
addressLineEdit->setObjectName(QStringLiteral("addressLineEdit")); addressLineEdit->setObjectName(QStringLiteral("addressLineEdit"));
addressLineEdit->setText(address.c_str()); addressLineEdit->setText(address.c_str());
QObject::connect(addressLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(addressLineEdit); horizontalLayout_2->addWidget(addressLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
bool isUniqueLocal = tunnelConfig->getisUniqueLocal(); bool isUniqueLocal = tunnelConfig->getisUniqueLocal();
@ -219,10 +243,12 @@ void ServerTunnelPane::appendServerTunnelForm(
ui.isUniqueLocalCheckBox = new QCheckBox(gridLayoutWidget_2); ui.isUniqueLocalCheckBox = new QCheckBox(gridLayoutWidget_2);
isUniqueLocalCheckBox->setObjectName(QStringLiteral("isUniqueLocalCheckBox")); isUniqueLocalCheckBox->setObjectName(QStringLiteral("isUniqueLocalCheckBox"));
isUniqueLocalCheckBox->setChecked(isUniqueLocal); isUniqueLocalCheckBox->setChecked(isUniqueLocal);
QObject::connect(gzipCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(isUniqueLocalCheckBox); horizontalLayout_2->addWidget(isUniqueLocalCheckBox);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
I2CPParameters& i2cpParameters = tunnelConfig->getI2cpParameters(); I2CPParameters& i2cpParameters = tunnelConfig->getI2cpParameters();
@ -232,16 +258,16 @@ void ServerTunnelPane::appendServerTunnelForm(
retranslateServerTunnelForm(ui); retranslateServerTunnelForm(ui);
tunnelGridLayout->invalidate(); tunnelGridLayout->invalidate();
}
void ServerTunnelPane::deleteServerTunnelForm(QGridLayout *tunnelsFormGridLayout) { return h;
tunnelsFormGridLayout->removeWidget(tunnelGroupBox); }
tunnelGroupBox->deleteLater(); void ServerTunnelPane::deleteServerTunnelForm() {
tunnelGroupBox=nullptr; delete serverTunnelNameGroupBox;//->deleteLater();
serverTunnelNameGroupBox=nullptr;
gridLayoutWidget_2->deleteLater(); //gridLayoutWidget_2->deleteLater();
gridLayoutWidget_2=nullptr; //gridLayoutWidget_2=nullptr;
} }

53
qt/i2pd_qt/ServerTunnelPane.h

@ -2,7 +2,7 @@
#define SERVERTUNNELPANE_H #define SERVERTUNNELPANE_H
#include "TunnelPane.h" #include "TunnelPane.h"
#include "mainwindow.h" #include "TunnelsPageUpdateListener.h"
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtWidgets/QAction> #include <QtWidgets/QAction>
@ -18,6 +18,10 @@
#include <QtWidgets/QPushButton> #include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem> #include <QtWidgets/QSpacerItem>
#include <QtWidgets/QWidget> #include <QtWidgets/QWidget>
#include "QVBoxLayout"
#include "QCheckBox"
#include "assert.h"
class ServerTunnelConfig; class ServerTunnelConfig;
@ -27,15 +31,15 @@ class ServerTunnelPane : public TunnelPane {
Q_OBJECT Q_OBJECT
public: public:
ServerTunnelPane(); ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf);
virtual ~ServerTunnelPane(){} virtual ~ServerTunnelPane(){}
virtual ServerTunnelPane* asServerTunnelPane(); virtual ServerTunnelPane* asServerTunnelPane();
virtual ClientTunnelPane* asClientTunnelPane(); virtual ClientTunnelPane* asClientTunnelPane();
void appendServerTunnelForm(ServerTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget, int appendServerTunnelForm(ServerTunnelConfig* tunnelConfig, QWidget *tunnelsFormGridLayoutWidget,
QGridLayout *tunnelsFormGridLayout, int tunnelsRow); int tunnelsRow, int height);
void deleteServerTunnelForm(QGridLayout *tunnelsFormGridLayout); void deleteServerTunnelForm();
private: private:
QGroupBox *serverTunnelNameGroupBox; QGroupBox *serverTunnelNameGroupBox;
@ -113,6 +117,45 @@ private:
sigTypeLabel->setText(QApplication::translate("cltTunForm", "Signature type:", 0)); sigTypeLabel->setText(QApplication::translate("cltTunForm", "Signature type:", 0));
} }
protected:
virtual bool applyDataFromUIToTunnelConfig() {
bool ok=TunnelPane::applyDataFromUIToTunnelConfig();
if(!ok)return false;
ServerTunnelConfig* stc=tunnelConfig->asServerTunnelConfig();
assert(stc!=nullptr);
stc->sethost(hostLineEdit->text().toStdString());
auto portStr=portLineEdit->text();
int portInt=portStr.toInt(&ok);
if(!ok)return false;
stc->setport(portInt);
stc->setkeys(keysLineEdit->text().toStdString());
auto str=inPortLineEdit->text();
int inPortInt=str.toInt(&ok);
if(!ok)return false;
stc->setinPort(inPortInt);
stc->setaccessList(accessListLineEdit->text().toStdString());
stc->sethostOverride(hostOverrideLineEdit->text().toStdString());
stc->setwebircpass(webIRCPassLineEdit->text().toStdString());
stc->setaddress(addressLineEdit->text().toStdString());
auto mcStr=maxConnsLineEdit->text();
uint32_t mcInt=(uint32_t)mcStr.toInt(&ok);
if(!ok)return false;
stc->setmaxConns(mcInt);
stc->setgzip(gzipCheckBox->isChecked());
stc->setisUniqueLocal(isUniqueLocalCheckBox->isChecked());
stc->setsigType(readSigTypeComboboxUI(sigTypeComboBox));
}
}; };
#endif // SERVERTUNNELPANE_H #endif // SERVERTUNNELPANE_H

2
qt/i2pd_qt/SignatureTypeComboboxFactory.h

@ -8,7 +8,7 @@
class SignatureTypeComboBoxFactory class SignatureTypeComboBoxFactory
{ {
static const QVariant& createUserData(const uint16_t sigType) { static const QVariant createUserData(const uint16_t sigType) {
return QVariant::fromValue((uint)sigType); return QVariant::fromValue((uint)sigType);
} }

39
qt/i2pd_qt/TunnelConfig.cpp

@ -1,2 +1,41 @@
#include "TunnelConfig.h" #include "TunnelConfig.h"
void TunnelConfig::saveHeaderToStringStream(std::stringstream& out) {
out << "[" << name << "]\n"
<< "type=" << type.toStdString() << "\n";
}
void TunnelConfig::saveI2CPParametersToStringStream(std::stringstream& out) {
out << "inbound.length=" << i2cpParameters.getInbound_length().toStdString() << "\n"
<< "outbound.length=" << i2cpParameters.getOutbound_length().toStdString() << "\n"
<< "inbound.quantity=" << i2cpParameters.getInbound_quantity().toStdString() << "\n"
<< "outbound.quantity=" << i2cpParameters.getOutbound_quantity().toStdString() << "\n"
<< "crypto.tagsToSend=" << i2cpParameters.getCrypto_tagsToSend().toStdString() << "\n"
<< "explicitPeers=" << i2cpParameters.getExplicitPeers().toStdString() << "\n\n";
}
void ClientTunnelConfig::saveToStringStream(std::stringstream& out) {
out << "address=" << address << "\n"
<< "port=" << port << "\n"
<< "destination=" << dest << "\n"
<< "keys=" << keys << "\n"
<< "destinationport=" << destinationPort << "\n"
<< "signaturetype=" << sigType << "\n";
}
void ServerTunnelConfig::saveToStringStream(std::stringstream& out) {
out << "host=" << host << "\n"
<< "port=" << port << "\n"
<< "keys=" << keys << "\n"
<< "signaturetype=" << sigType << "\n"
<< "inport=" << inPort << "\n"
<< "accesslist=" << accessList << "\n"
<< "gzip=" << (gzip?"true":"false") << "\n"
<< "enableuniquelocal=" << (isUniqueLocal?"true":"false") << "\n"
<< "address=" << address << "\n"
<< "hostoverride=" << hostOverride << "\n"
<< "webircpassword=" << webircpass << "\n"
<< "maxconns=" << maxConns << "\n";
}

27
qt/i2pd_qt/TunnelConfig.h

@ -5,6 +5,7 @@
#include <string> #include <string>
#include "../../ClientContext.h" #include "../../ClientContext.h"
#include "TunnelsPageUpdateListener.h"
class I2CPParameters{ class I2CPParameters{
@ -53,13 +54,17 @@ class TunnelConfig {
QString type; QString type;
std::string name; std::string name;
public: public:
TunnelConfig(std::string name_, QString& type_, I2CPParameters& i2cpParameters_): type(type_), name(name_), i2cpParameters(i2cpParameters_) {} TunnelConfig(std::string name_, QString& type_, I2CPParameters& i2cpParameters_):
type(type_), name(name_), i2cpParameters(i2cpParameters_) {}
virtual ~TunnelConfig(){} virtual ~TunnelConfig(){}
const QString& getType(){return type;} const QString& getType(){return type;}
const std::string& getName(){return name;} const std::string& getName(){return name;}
void setType(const QString& type_){type=type_;} void setType(const QString& type_){type=type_;}
void setName(const std::string& name_){name=name_;} void setName(const std::string& name_){name=name_;}
I2CPParameters& getI2cpParameters(){return i2cpParameters;} I2CPParameters& getI2cpParameters(){return i2cpParameters;}
void saveHeaderToStringStream(std::stringstream& out);
void saveI2CPParametersToStringStream(std::stringstream& out);
virtual void saveToStringStream(std::stringstream& out)=0;
virtual ClientTunnelConfig* asClientTunnelConfig()=0; virtual ClientTunnelConfig* asClientTunnelConfig()=0;
virtual ServerTunnelConfig* asServerTunnelConfig()=0; virtual ServerTunnelConfig* asServerTunnelConfig()=0;
@ -116,12 +121,13 @@ public:
std::string & getaddress(){return address;} std::string & getaddress(){return address;}
int getdestinationPort(){return destinationPort;} int getdestinationPort(){return destinationPort;}
i2p::data::SigningKeyType getsigType(){return sigType;} i2p::data::SigningKeyType getsigType(){return sigType;}
void setdest(std::string& dest_){dest=dest_;} void setdest(const std::string& dest_){dest=dest_;}
void setport(int port_){port=port_;} void setport(int port_){port=port_;}
void setkeys(std::string & keys_){keys=keys_;} void setkeys(const std::string & keys_){keys=keys_;}
void setaddress(std::string & address_){address=address_;} void setaddress(const std::string & address_){address=address_;}
void setdestinationPort(int destinationPort_){destinationPort=destinationPort_;} void setdestinationPort(int destinationPort_){destinationPort=destinationPort_;}
void setsigType(i2p::data::SigningKeyType sigType_){sigType=sigType_;} void setsigType(i2p::data::SigningKeyType sigType_){sigType=sigType_;}
virtual void saveToStringStream(std::stringstream& out);
virtual ClientTunnelConfig* asClientTunnelConfig(){return this;} virtual ClientTunnelConfig* asClientTunnelConfig(){return this;}
virtual ServerTunnelConfig* asServerTunnelConfig(){return nullptr;} virtual ServerTunnelConfig* asServerTunnelConfig(){return nullptr;}
}; };
@ -203,18 +209,19 @@ public:
uint32_t getmaxConns(){return maxConns;} uint32_t getmaxConns(){return maxConns;}
std::string& getaddress(){return address;} std::string& getaddress(){return address;}
bool getisUniqueLocal(){return isUniqueLocal;} bool getisUniqueLocal(){return isUniqueLocal;}
void sethost(std::string& host_){host=host_;} void sethost(const std::string& host_){host=host_;}
void setport(int port_){port=port_;} void setport(int port_){port=port_;}
void setkeys(std::string& keys_){keys=keys_;} void setkeys(const std::string& keys_){keys=keys_;}
void setinPort(int inPort_){inPort=inPort_;} void setinPort(int inPort_){inPort=inPort_;}
void setaccessList(std::string& accessList_){accessList=accessList_;} void setaccessList(const std::string& accessList_){accessList=accessList_;}
void sethostOverride(std::string& hostOverride_){hostOverride=hostOverride_;} void sethostOverride(const std::string& hostOverride_){hostOverride=hostOverride_;}
void setwebircpass(std::string& webircpass_){webircpass=webircpass_;} void setwebircpass(const std::string& webircpass_){webircpass=webircpass_;}
void setgzip(bool gzip_){gzip=gzip_;} void setgzip(bool gzip_){gzip=gzip_;}
void setsigType(i2p::data::SigningKeyType sigType_){sigType=sigType_;} void setsigType(i2p::data::SigningKeyType sigType_){sigType=sigType_;}
void setmaxConns(uint32_t maxConns_){maxConns=maxConns_;} void setmaxConns(uint32_t maxConns_){maxConns=maxConns_;}
void setaddress(std::string& address_){address=address_;} void setaddress(const std::string& address_){address=address_;}
void setisUniqueLocal(bool isUniqueLocal_){isUniqueLocal=isUniqueLocal_;} void setisUniqueLocal(bool isUniqueLocal_){isUniqueLocal=isUniqueLocal_;}
virtual void saveToStringStream(std::stringstream& out);
virtual ClientTunnelConfig* asClientTunnelConfig(){return nullptr;} virtual ClientTunnelConfig* asClientTunnelConfig(){return nullptr;}
virtual ServerTunnelConfig* asServerTunnelConfig(){return this;} virtual ServerTunnelConfig* asServerTunnelConfig(){return this;}
}; };

94
qt/i2pd_qt/TunnelPane.cpp

@ -1,26 +1,32 @@
#include "TunnelPane.h" #include "TunnelPane.h"
#include "QMessageBox"
TunnelPane::TunnelPane(): QObject(),gridLayoutWidget_2(nullptr) { TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_):
} QObject(),
tunnelConfig(tunnelConfig_),
tunnelsPageUpdateListener(tunnelsPageUpdateListener_),
gridLayoutWidget_2(nullptr) {}
void TunnelPane::setupTunnelPane( void TunnelPane::setupTunnelPane(
TunnelConfig* tunnelConfig, TunnelConfig* tunnelConfig,
QGroupBox *tunnelGroupBox, QGroupBox *tunnelGroupBox,
QWidget* gridLayoutWidget_2, QComboBox * tunnelTypeComboBox, QWidget* gridLayoutWidget_2, QComboBox * tunnelTypeComboBox,
QWidget *tunnelsFormGridLayoutWidget, QGridLayout *tunnelsFormGridLayout, int tunnelsRow) { QWidget *tunnelsFormGridLayoutWidget, int tunnelsRow, int height, int h) {
tunnelsFormGridLayoutWidget->resize(527, tunnelsFormGridLayoutWidget->height()+gridLayoutWidget_2->height()); tunnelGroupBox->setGeometry(0, tunnelsFormGridLayoutWidget->height(), gridLayoutWidget_2->width(), h);
tunnelGroupBox->resize(gridLayoutWidget_2->width(), gridLayoutWidget_2->height()); tunnelsFormGridLayoutWidget->resize(527, tunnelsFormGridLayoutWidget->height()+h);
tunnelsFormGridLayout->addWidget(tunnelGroupBox, tunnelsRow, 0);
QObject::connect(tunnelTypeComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updated()));
this->tunnelGroupBox=tunnelGroupBox; this->tunnelGroupBox=tunnelGroupBox;
gridLayoutWidget_2->setObjectName(QStringLiteral("gridLayoutWidget_2")); gridLayoutWidget_2->setObjectName(QStringLiteral("gridLayoutWidget_2"));
this->gridLayoutWidget_2=gridLayoutWidget_2; this->gridLayoutWidget_2=gridLayoutWidget_2;
tunnelGridLayout = new QGridLayout(gridLayoutWidget_2); tunnelGridLayout = new QVBoxLayout(gridLayoutWidget_2);
tunnelGridLayout->setObjectName(QStringLiteral("tunnelGridLayout")); tunnelGridLayout->setObjectName(QStringLiteral("tunnelGridLayout"));
tunnelGridLayout->setContentsMargins(5, 5, 5, 5); tunnelGridLayout->setContentsMargins(5, 5, 5, 5);
tunnelGridLayout->setVerticalSpacing(5); tunnelGridLayout->setSpacing(5);
//header //header
QHBoxLayout *headerHorizontalLayout = new QHBoxLayout(); QHBoxLayout *headerHorizontalLayout = new QHBoxLayout();
@ -37,14 +43,18 @@ void TunnelPane::setupTunnelPane(
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)), QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(setGroupBoxTitle(const QString &))); this, SLOT(setGroupBoxTitle(const QString &)));
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
headerHorizontalLayout->addWidget(nameLineEdit); headerHorizontalLayout->addWidget(nameLineEdit);
headerHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); headerHorizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
headerHorizontalLayout->addItem(headerHorizontalSpacer); headerHorizontalLayout->addItem(headerHorizontalSpacer);
deletePushButton = new QPushButton(gridLayoutWidget_2);//TODO handle it deletePushButton = new QPushButton(gridLayoutWidget_2);
deletePushButton->setObjectName(QStringLiteral("deletePushButton")); deletePushButton->setObjectName(QStringLiteral("deletePushButton"));
QObject::connect(deletePushButton, SIGNAL(released()),
this, SLOT(deleteButtonReleased()));//MainWindow::DeleteTunnelNamed(std::string name) {
headerHorizontalLayout->addWidget(deletePushButton); headerHorizontalLayout->addWidget(deletePushButton);
tunnelGridLayout->addLayout(headerHorizontalLayout, 0, 0, 1, 1); tunnelGridLayout->addLayout(headerHorizontalLayout);
//type //type
{ {
@ -58,7 +68,7 @@ void TunnelPane::setupTunnelPane(
this->tunnelTypeComboBox=tunnelTypeComboBox; this->tunnelTypeComboBox=tunnelTypeComboBox;
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_->addItem(horizontalSpacer); horizontalLayout_->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_, 1, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_);
} }
retranslateTunnelForm(*this); retranslateTunnelForm(*this);
@ -77,10 +87,12 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters,
inbound_lengthLineEdit->setObjectName(QStringLiteral("inbound_lengthLineEdit")); inbound_lengthLineEdit->setObjectName(QStringLiteral("inbound_lengthLineEdit"));
inbound_lengthLineEdit->setText(inbound_length); inbound_lengthLineEdit->setText(inbound_length);
inbound_lengthLineEdit->setMaximumWidth(80); inbound_lengthLineEdit->setMaximumWidth(80);
QObject::connect(inbound_lengthLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(inbound_lengthLineEdit); horizontalLayout_2->addWidget(inbound_lengthLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
//number of hops of an outbound tunnel //number of hops of an outbound tunnel
@ -94,10 +106,12 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters,
outbound_lengthLineEdit->setObjectName(QStringLiteral("outbound_lengthLineEdit")); outbound_lengthLineEdit->setObjectName(QStringLiteral("outbound_lengthLineEdit"));
outbound_lengthLineEdit->setText(outbound_length); outbound_lengthLineEdit->setText(outbound_length);
outbound_lengthLineEdit->setMaximumWidth(80); outbound_lengthLineEdit->setMaximumWidth(80);
QObject::connect(outbound_lengthLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(outbound_lengthLineEdit); horizontalLayout_2->addWidget(outbound_lengthLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
//number of inbound tunnels //number of inbound tunnels
@ -111,10 +125,12 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters,
inbound_quantityLineEdit->setObjectName(QStringLiteral("inbound_quantityLineEdit")); inbound_quantityLineEdit->setObjectName(QStringLiteral("inbound_quantityLineEdit"));
inbound_quantityLineEdit->setText(inbound_quantity); inbound_quantityLineEdit->setText(inbound_quantity);
inbound_quantityLineEdit->setMaximumWidth(80); inbound_quantityLineEdit->setMaximumWidth(80);
QObject::connect(inbound_quantityLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(inbound_quantityLineEdit); horizontalLayout_2->addWidget(inbound_quantityLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
//number of outbound tunnels //number of outbound tunnels
@ -128,10 +144,12 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters,
outbound_quantityLineEdit->setObjectName(QStringLiteral("outbound_quantityLineEdit")); outbound_quantityLineEdit->setObjectName(QStringLiteral("outbound_quantityLineEdit"));
outbound_quantityLineEdit->setText(outbound_quantity); outbound_quantityLineEdit->setText(outbound_quantity);
outbound_quantityLineEdit->setMaximumWidth(80); outbound_quantityLineEdit->setMaximumWidth(80);
QObject::connect(outbound_quantityLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(outbound_quantityLineEdit); horizontalLayout_2->addWidget(outbound_quantityLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
{ {
//number of ElGamal/AES tags to send //number of ElGamal/AES tags to send
@ -145,11 +163,55 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters,
crypto_tagsToSendLineEdit->setObjectName(QStringLiteral("crypto_tagsToSendLineEdit")); crypto_tagsToSendLineEdit->setObjectName(QStringLiteral("crypto_tagsToSendLineEdit"));
crypto_tagsToSendLineEdit->setText(crypto_tagsToSend); crypto_tagsToSendLineEdit->setText(crypto_tagsToSend);
crypto_tagsToSendLineEdit->setMaximumWidth(80); crypto_tagsToSendLineEdit->setMaximumWidth(80);
QObject::connect(crypto_tagsToSendLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
horizontalLayout_2->addWidget(crypto_tagsToSendLineEdit); horizontalLayout_2->addWidget(crypto_tagsToSendLineEdit);
QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem * horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer); horizontalLayout_2->addItem(horizontalSpacer);
tunnelGridLayout->addLayout(horizontalLayout_2, ++gridIndex, 0, 1, 1); tunnelGridLayout->addLayout(horizontalLayout_2);
} }
retranslateI2CPParameters(); retranslateI2CPParameters();
} }
void TunnelPane::updated() {
std::string oldName=tunnelConfig->getName();
if(!applyDataFromUIToTunnelConfig())return;//TODO visualise bad input
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
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();
}

34
qt/i2pd_qt/TunnelPane.h

@ -10,6 +10,7 @@
#include "QApplication" #include "QApplication"
#include "QLineEdit" #include "QLineEdit"
#include "QGroupBox" #include "QGroupBox"
#include "QVBoxLayout"
#include "TunnelConfig.h" #include "TunnelConfig.h"
@ -24,20 +25,30 @@ class TunnelPane : public QObject {
Q_OBJECT Q_OBJECT
public: public:
TunnelPane(); TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunconf);
virtual ~TunnelPane(){} virtual ~TunnelPane(){}
virtual ServerTunnelPane* asServerTunnelPane()=0; virtual ServerTunnelPane* asServerTunnelPane()=0;
virtual ClientTunnelPane* asClientTunnelPane()=0; virtual ClientTunnelPane* asClientTunnelPane()=0;
protected: protected:
QGridLayout *tunnelGridLayout; TunnelConfig* tunnelConfig;
TunnelsPageUpdateListener* tunnelsPageUpdateListener;
QVBoxLayout *tunnelGridLayout;
QGroupBox *tunnelGroupBox; QGroupBox *tunnelGroupBox;
QWidget* gridLayoutWidget_2; QWidget* gridLayoutWidget_2;
//header //header
QLabel *nameLabel; QLabel *nameLabel;
QLineEdit *nameLineEdit; QLineEdit *nameLineEdit;
public:
QLineEdit * getNameLineEdit() { return nameLineEdit; }
public slots:
void updated();
void deleteButtonReleased();
protected:
QSpacerItem *headerHorizontalSpacer; QSpacerItem *headerHorizontalSpacer;
QPushButton *deletePushButton; QPushButton *deletePushButton;
@ -62,11 +73,28 @@ protected:
QLabel * crypto_tagsToSendLabel; QLabel * crypto_tagsToSendLabel;
QLineEdit * crypto_tagsToSendLineEdit; QLineEdit * crypto_tagsToSendLineEdit;
QString readTunnelTypeComboboxData();
//should be created by factory
i2p::data::SigningKeyType readSigTypeComboboxUI(QComboBox* sigTypeComboBox);
//returns false when invalid data at UI
virtual bool applyDataFromUIToTunnelConfig() {
tunnelConfig->setName(nameLineEdit->text().toStdString());
tunnelConfig->setType(readTunnelTypeComboboxData());
I2CPParameters& i2cpParams=tunnelConfig->getI2cpParameters();
i2cpParams.setInbound_length(inbound_lengthLineEdit->text());
i2cpParams.setInbound_quantity(inbound_quantityLineEdit->text());
i2cpParams.setOutbound_length(outbound_lengthLineEdit->text());
i2cpParams.setOutbound_quantity(outbound_quantityLineEdit->text());
i2cpParams.setCrypto_tagsToSend(crypto_tagsToSendLineEdit->text());
}
void setupTunnelPane( void setupTunnelPane(
TunnelConfig* tunnelConfig, TunnelConfig* tunnelConfig,
QGroupBox *tunnelGroupBox, QGroupBox *tunnelGroupBox,
QWidget* gridLayoutWidget_2, QComboBox * tunnelTypeComboBox, QWidget* gridLayoutWidget_2, QComboBox * tunnelTypeComboBox,
QWidget *tunnelsFormGridLayoutWidget, QGridLayout *tunnelsFormGridLayout, int tunnelsRow); QWidget *tunnelsFormGridLayoutWidget, int tunnelsRow, int height, int h);
void appendControlsForI2CPParameters(I2CPParameters& i2cpParameters, int& gridIndex); void appendControlsForI2CPParameters(I2CPParameters& i2cpParameters, int& gridIndex);
public: public:
int height() { int height() {

12
qt/i2pd_qt/TunnelsPageUpdateListener.h

@ -0,0 +1,12 @@
#ifndef TUNNELSPAGEUPDATELISTENER_H
#define TUNNELSPAGEUPDATELISTENER_H
class TunnelConfig;
class TunnelsPageUpdateListener {
public:
virtual void updated(std::string oldName, TunnelConfig* tunConf)=0;
virtual void needsDeleting(std::string oldName)=0;
};
#endif // TUNNELSPAGEUPDATELISTENER_H

107
qt/i2pd_qt/mainwindow.cpp

@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent) :
,datadir() ,datadir()
,confpath() ,confpath()
,tunconfpath() ,tunconfpath()
,tunnelsPageUpdateListener(this)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -185,16 +186,12 @@ MainWindow::MainWindow(QWidget *parent) :
loadAllConfigs(); loadAllConfigs();
tunnelsFormGridLayoutWidget = new QWidget(ui->tunnelsScrollAreaWidgetContents); //tunnelsFormGridLayoutWidget = new QWidget(ui->tunnelsScrollAreaWidgetContents);
tunnelsFormGridLayoutWidget->setObjectName(QStringLiteral("tunnelsFormGridLayoutWidget")); //tunnelsFormGridLayoutWidget->setObjectName(QStringLiteral("tunnelsFormGridLayoutWidget"));
tunnelsFormGridLayoutWidget->setGeometry(QRect(0, 0, 621, 451)); //tunnelsFormGridLayoutWidget->setGeometry(QRect(0, 0, 621, 451));
ui->tunnelsScrollAreaWidgetContents->setGeometry(QRect(0, 0, 621, 451)); ui->tunnelsScrollAreaWidgetContents->setGeometry(QRect(0, 0, 621, 451));
tunnelsFormGridLayout = new QGridLayout(tunnelsFormGridLayoutWidget);
tunnelsFormGridLayout->setObjectName(QStringLiteral("tunnelsFormGridLayout"));
tunnelsFormGridLayout->setContentsMargins(5, 5, 5, 5);
tunnelsFormGridLayout->setVerticalSpacing(5);
appendTunnelForms(); appendTunnelForms("");
ui->configFileLineEdit->setEnabled(false); ui->configFileLineEdit->setEnabled(false);
ui->configFileBrowsePushButton->setEnabled(false); ui->configFileBrowsePushButton->setEnabled(false);
@ -209,6 +206,8 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(ui->tunnelsConfigFileLineEdit, SIGNAL(textChanged(const QString &)), QObject::connect(ui->tunnelsConfigFileLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(reloadTunnelsConfigAndUI())); this, SLOT(reloadTunnelsConfigAndUI()));
QObject::connect(ui->addServerTunnelPushButton, SIGNAL(released()), this, SLOT(addServerTunnelPushButtonReleased()));
QObject::connect(ui->addClientTunnelPushButton, SIGNAL(released()), this, SLOT(addClientTunnelPushButtonReleased()));
#ifndef ANDROID #ifndef ANDROID
@ -476,10 +475,11 @@ bool MainWindow::saveAllConfigs(){
QFile::rename(confpath, backup);//TODO handle errors QFile::rename(confpath, backup);//TODO handle errors
ofstream outfile; ofstream outfile;
outfile.open(confpath.toStdString());//TODO handle errors outfile.open(confpath.toStdString());//TODO handle errors
string dataToWrite = out.str(); outfile << out.str().c_str();
outfile << dataToWrite.c_str();
outfile.close(); outfile.close();
SaveTunnelsConfig();
return true; return true;
} }
@ -507,47 +507,53 @@ void CheckBoxItem::installListeners(MainWindow *mainWindow) {
void MainWindowItem::installListeners(MainWindow *mainWindow) {} void MainWindowItem::installListeners(MainWindow *mainWindow) {}
void MainWindow::appendTunnelForms() { void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) {
int height=0; int height=0;
tunnelsFormGridLayoutWidget->setGeometry(0,0,0,0); ui->tunnelsScrollAreaWidgetContents->setGeometry(0,0,0,0);
for(std::list<TunnelConfig*>::iterator it = tunnelConfigs.begin(); it != tunnelConfigs.end(); ++it) { for(std::map<std::string, TunnelConfig*>::iterator it = tunnelConfigs.begin(); it != tunnelConfigs.end(); ++it) {
TunnelConfig* tunconf = *it; const std::string& name=it->first;
TunnelConfig* tunconf = it->second;
ServerTunnelConfig* stc = tunconf->asServerTunnelConfig(); ServerTunnelConfig* stc = tunconf->asServerTunnelConfig();
if(stc){ if(stc){
ServerTunnelPane * tunnelPane=new ServerTunnelPane(); ServerTunnelPane * tunnelPane=new ServerTunnelPane(&tunnelsPageUpdateListener, stc);
tunnelPane->appendServerTunnelForm(stc, tunnelsFormGridLayoutWidget, tunnelsFormGridLayout, tunnelPanes.size()); int h=tunnelPane->appendServerTunnelForm(stc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height);
height+=tunnelPane->height(); height+=h;
qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size(); qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
tunnelPanes.push_back(tunnelPane); tunnelPanes.push_back(tunnelPane);
if(name==tunnelNameToFocus)tunnelPane->getNameLineEdit()->setFocus();
continue; continue;
} }
ClientTunnelConfig* ctc = tunconf->asClientTunnelConfig(); ClientTunnelConfig* ctc = tunconf->asClientTunnelConfig();
if(ctc){ if(ctc){
ClientTunnelPane * tunnelPane=new ClientTunnelPane(); ClientTunnelPane * tunnelPane=new ClientTunnelPane(&tunnelsPageUpdateListener, ctc);
tunnelPane->appendClientTunnelForm(ctc, tunnelsFormGridLayoutWidget, tunnelsFormGridLayout, tunnelPanes.size()); int h=tunnelPane->appendClientTunnelForm(ctc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height);
height+=tunnelPane->height(); height+=h;
qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size(); qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
tunnelPanes.push_back(tunnelPane); tunnelPanes.push_back(tunnelPane);
if(name==tunnelNameToFocus)tunnelPane->getNameLineEdit()->setFocus();
continue; continue;
} }
throw "unknown TunnelConfig subtype"; throw "unknown TunnelConfig subtype";
} }
qDebug() << "tun.setting height:" << height; qDebug() << "tun.setting height:" << height;
tunnelsFormGridLayoutWidget->setGeometry(QRect(0, 0, 621, height));
tunnelsFormGridLayout->invalidate();
ui->tunnelsScrollAreaWidgetContents->setGeometry(QRect(0, 0, 621, height)); ui->tunnelsScrollAreaWidgetContents->setGeometry(QRect(0, 0, 621, height));
QList<QWidget*> childWidgets = ui->tunnelsScrollAreaWidgetContents->findChildren<QWidget*>();
foreach(QWidget* widget, childWidgets)
widget->show();
} }
void MainWindow::deleteTunnelForms() { void MainWindow::deleteTunnelForms() {
for(std::list<TunnelPane*>::iterator it = tunnelPanes.begin(); it != tunnelPanes.end(); ++it) { for(std::list<TunnelPane*>::iterator it = tunnelPanes.begin(); it != tunnelPanes.end(); ++it) {
TunnelPane* tp = *it; TunnelPane* tp = *it;
ServerTunnelPane* stp = tp->asServerTunnelPane(); ServerTunnelPane* stp = tp->asServerTunnelPane();
if(stp){ if(stp){
stp->deleteServerTunnelForm(tunnelsFormGridLayout); stp->deleteServerTunnelForm();
delete stp;
continue; continue;
} }
ClientTunnelPane* ctp = tp->asClientTunnelPane(); ClientTunnelPane* ctp = tp->asClientTunnelPane();
if(ctp){ if(ctp){
ctp->deleteClientTunnelForm(tunnelsFormGridLayout); ctp->deleteClientTunnelForm();
delete ctp;
continue; continue;
} }
throw "unknown TunnelPane subtype"; throw "unknown TunnelPane subtype";
@ -555,13 +561,58 @@ void MainWindow::deleteTunnelForms() {
tunnelPanes.clear(); tunnelPanes.clear();
} }
void MainWindow::reloadTunnelsConfigAndUI() { void MainWindow::reloadTunnelsConfigAndUI(std::string tunnelNameToFocus) {
deleteTunnelForms(); deleteTunnelForms();
for(std::list<TunnelConfig*>::iterator it = tunnelConfigs.begin(); it != tunnelConfigs.end(); ++it) { for (std::map<std::string,TunnelConfig*>::iterator it=tunnelConfigs.begin(); it!=tunnelConfigs.end(); ++it) {
TunnelConfig* tunconf = *it; TunnelConfig* tunconf = it->second;
delete tunconf; delete tunconf;
} }
tunnelConfigs.clear(); tunnelConfigs.clear();
ReadTunnelsConfig(); ReadTunnelsConfig();
appendTunnelForms(); appendTunnelForms(tunnelNameToFocus);
}
void MainWindow::SaveTunnelsConfig() {
std::stringstream out;
for (std::map<std::string,TunnelConfig*>::iterator it=tunnelConfigs.begin(); it!=tunnelConfigs.end(); ++it) {
const std::string& name = it->first;
TunnelConfig* tunconf = it->second;
tunconf->saveHeaderToStringStream(out);
tunconf->saveToStringStream(out);
tunconf->saveI2CPParametersToStringStream(out);
}
using namespace std;
QString backup=tunconfpath+"~";
if(QFile::exists(backup)) QFile::remove(backup);//TODO handle errors
QFile::rename(tunconfpath, backup);//TODO handle errors
ofstream outfile;
outfile.open(tunconfpath.toStdString());//TODO handle errors
outfile << out.str().c_str();
outfile.close();
}
void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string oldName, TunnelConfig* tunConf) {
if(oldName!=tunConf->getName()) {
//name has changed
std::map<std::string,TunnelConfig*>::const_iterator it=mainWindow->tunnelConfigs.find(oldName);
if(it!=mainWindow->tunnelConfigs.end())mainWindow->tunnelConfigs.erase(it);
mainWindow->tunnelConfigs[tunConf->getName()]=tunConf;
}
mainWindow->SaveTunnelsConfig();
}
void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::needsDeleting(std::string oldName){
mainWindow->DeleteTunnelNamed(oldName);
}
void MainWindow::addServerTunnelPushButtonReleased() {
CreateDefaultServerTunnel();
}
void MainWindow::addClientTunnelPushButtonReleased() {
CreateDefaultClientTunnel();
} }

137
qt/i2pd_qt/mainwindow.h

@ -23,6 +23,7 @@
#include <QtWidgets/QLineEdit> #include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton> #include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem> #include <QtWidgets/QSpacerItem>
#include "QVBoxLayout"
#ifndef ANDROID #ifndef ANDROID
# include <QSystemTrayIcon> # include <QSystemTrayIcon>
@ -48,6 +49,8 @@
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "TunnelsPageUpdateListener.h"
template<typename ValueType> template<typename ValueType>
bool isType(boost::any& a) { bool isType(boost::any& a) {
return return
@ -380,20 +383,23 @@ protected:
public slots: public slots:
/** returns false iff not valid items present and save was aborted */ /** returns false iff not valid items present and save was aborted */
bool saveAllConfigs(); bool saveAllConfigs();
void reloadTunnelsConfigAndUI(); void SaveTunnelsConfig();
void reloadTunnelsConfigAndUI(std::string tunnelNameToFocus);
//focus none
void reloadTunnelsConfigAndUI() { reloadTunnelsConfigAndUI(""); }
void addServerTunnelPushButtonReleased();
void addClientTunnelPushButtonReleased();
private: private:
QString datadir; QString datadir;
QString confpath; QString confpath;
QString tunconfpath; QString tunconfpath;
std::list<TunnelConfig*> tunnelConfigs; std::map<std::string, TunnelConfig*> tunnelConfigs;
std::list<TunnelPane*> tunnelPanes; std::list<TunnelPane*> tunnelPanes;
QWidget *tunnelsFormGridLayoutWidget; void appendTunnelForms(std::string tunnelNameToFocus);
QGridLayout *tunnelsFormGridLayout;
void appendTunnelForms();
void deleteTunnelForms(); void deleteTunnelForms();
@ -427,6 +433,107 @@ private:
options[I2CP_PARAM_MAX_TUNNEL_LATENCY] = GetI2CPOption(section, I2CP_PARAM_MAX_TUNNEL_LATENCY, DEFAULT_MAX_TUNNEL_LATENCY);//TODO include into param options[I2CP_PARAM_MAX_TUNNEL_LATENCY] = GetI2CPOption(section, I2CP_PARAM_MAX_TUNNEL_LATENCY, DEFAULT_MAX_TUNNEL_LATENCY);//TODO include into param
} }
void CreateDefaultI2CPOptions (I2CPParameters& param
/*TODO fill param*/) const
{
const int _INBOUND_TUNNEL_LENGTH = DEFAULT_INBOUND_TUNNEL_LENGTH;
param.setInbound_length(QString::number(_INBOUND_TUNNEL_LENGTH));
const int _OUTBOUND_TUNNEL_LENGTH = DEFAULT_OUTBOUND_TUNNEL_LENGTH;
param.setOutbound_length(QString::number(_OUTBOUND_TUNNEL_LENGTH));
const int _INBOUND_TUNNELS_QUANTITY = DEFAULT_INBOUND_TUNNELS_QUANTITY;
param.setInbound_quantity( QString::number(_INBOUND_TUNNELS_QUANTITY));
const int _OUTBOUND_TUNNELS_QUANTITY = DEFAULT_OUTBOUND_TUNNELS_QUANTITY;
param.setOutbound_quantity(QString::number(_OUTBOUND_TUNNELS_QUANTITY));
const int _TAGS_TO_SEND = DEFAULT_TAGS_TO_SEND;
param.setCrypto_tagsToSend(QString::number(_TAGS_TO_SEND));
}
void DeleteTunnelNamed(std::string name) {
std::map<std::string,TunnelConfig*>::const_iterator it=tunnelConfigs.find(name);
if(it!=tunnelConfigs.end()){
TunnelConfig* tc=it->second;
tunnelConfigs.erase(it);
delete tc;
SaveTunnelsConfig();
reloadTunnelsConfigAndUI("");
}
}
std::string GenerateNewTunnelName() {
int i=1;
while(true){
std::stringstream name;
name << "name" << i;
const std::string& str=name.str();
if(tunnelConfigs.find(str)==tunnelConfigs.end())return str;
++i;
}
}
void CreateDefaultClientTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
std::string name=GenerateNewTunnelName();
std::string type = I2P_TUNNELS_SECTION_TYPE_CLIENT;
std::string dest = "127.0.0.1";
int port = 0;
std::string keys = "";
std::string address = "127.0.0.1";
int destinationPort = 0;
i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256;
// I2CP
I2CPParameters i2cpParameters;
CreateDefaultI2CPOptions (i2cpParameters);
tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
dest,
port,
keys,
address,
destinationPort,
sigType);
SaveTunnelsConfig();
reloadTunnelsConfigAndUI(name);
}
void CreateDefaultServerTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
std::string name=GenerateNewTunnelName();
std::string type=I2P_TUNNELS_SECTION_TYPE_SERVER;
std::string host = "127.0.0.1";
int port = 0;
std::string keys = "";
int inPort = 0;
std::string accessList = "";
std::string hostOverride = "";
std::string webircpass = "";
bool gzip = true;
i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256;
uint32_t maxConns = i2p::stream::DEFAULT_MAX_CONNS_PER_MIN;
std::string address = "127.0.0.1";
bool isUniqueLocal = true;
// I2CP
I2CPParameters i2cpParameters;
CreateDefaultI2CPOptions (i2cpParameters);
tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
host,
port,
keys,
inPort,
accessList,
hostOverride,
webircpass,
gzip,
sigType,
maxConns,
address,
isUniqueLocal);
SaveTunnelsConfig();
reloadTunnelsConfigAndUI(name);
}
void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels () void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels ()
{ {
@ -479,13 +586,13 @@ private:
I2CPParameters i2cpParameters; I2CPParameters i2cpParameters;
ReadI2CPOptions (section, options, i2cpParameters); ReadI2CPOptions (section, options, i2cpParameters);
tunnelConfigs.push_back(new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters, tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
dest, dest,
port, port,
keys, keys,
address, address,
destinationPort, destinationPort,
sigType)); sigType);
} }
else if (type == I2P_TUNNELS_SECTION_TYPE_SERVER else if (type == I2P_TUNNELS_SECTION_TYPE_SERVER
|| type == I2P_TUNNELS_SECTION_TYPE_HTTP || type == I2P_TUNNELS_SECTION_TYPE_HTTP
@ -528,7 +635,7 @@ private:
while (comma != std::string::npos); while (comma != std::string::npos);
} }
*/ */
tunnelConfigs.push_back(new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters, tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
host, host,
port, port,
keys, keys,
@ -540,7 +647,7 @@ private:
sigType, sigType,
maxConns, maxConns,
address, address,
isUniqueLocal)); isUniqueLocal);
} }
else else
LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", tunConf);//TODO show err box and disable the tunn gui LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", tunConf);//TODO show err box and disable the tunn gui
@ -553,6 +660,16 @@ private:
} }
} }
private:
class TunnelsPageUpdateListenerMainWindowImpl : public TunnelsPageUpdateListener {
MainWindow* mainWindow;
public:
TunnelsPageUpdateListenerMainWindowImpl(MainWindow* mainWindow_):mainWindow(mainWindow_){}
virtual void updated(std::string oldName, TunnelConfig* tunConf);
virtual void needsDeleting(std::string oldName);
};
TunnelsPageUpdateListenerMainWindowImpl tunnelsPageUpdateListener;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

54
qt/i2pd_qt/mainwindow.ui

@ -136,7 +136,7 @@
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="statusPage"> <widget class="QWidget" name="statusPage">
<widget class="QWidget" name="verticalLayoutWidget_5"> <widget class="QWidget" name="verticalLayoutWidget_5">
@ -193,7 +193,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>701</width> <width>701</width>
<height>450</height> <height>400</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -231,8 +231,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>683</width> <width>679</width>
<height>416</height> <height>400</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -246,12 +246,13 @@
<rect> <rect>
<x>10</x> <x>10</x>
<y>11</y> <y>11</y>
<width>661</width> <width>679</width>
<height>3048</height> <height>2962</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="settingsContentsGridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"> <layout class="QGridLayout" name="settingsContentsGridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0">
<item row="14" column="0"> <item row="14" column="0">
<widget class="QGroupBox" name="samGroupBox"> <widget class="QGroupBox" name="samGroupBox">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -281,7 +282,7 @@
<string>Enabled</string> <string>Enabled</string>
</property> </property>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_8"> <widget class="QWidget" name="sam_horizontalLayoutWidget_8">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -290,9 +291,9 @@
<height>31</height> <height>31</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_25"> <layout class="QHBoxLayout" name="sam_horizontalLayout_25">
<item> <item>
<widget class="QLabel" name="label_24"> <widget class="QLabel" name="sam_label_24">
<property name="text"> <property name="text">
<string>IP address to listen on:</string> <string>IP address to listen on:</string>
</property> </property>
@ -302,7 +303,7 @@
<widget class="QLineEdit" name="samAddressLineEdit"/> <widget class="QLineEdit" name="samAddressLineEdit"/>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_19"> <spacer name="sam_horizontalSpacer_19">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -316,18 +317,18 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_9"> <widget class="QWidget" name="sam_horizontalLayoutWidget_9">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>70</y> <y>70</y>
<width>661</width> <width>661</width>
<height>342</height> <height>31</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_26"> <layout class="QHBoxLayout" name="sam_horizontalLayout_26">
<item> <item>
<widget class="QLabel" name="label_25"> <widget class="QLabel" name="sam_label_25">
<property name="text"> <property name="text">
<string>Port to listen on:</string> <string>Port to listen on:</string>
</property> </property>
@ -344,7 +345,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_20"> <spacer name="sam_horizontalSpacer_20">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -359,6 +360,9 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="8" column="0">
<widget class="QLabel" name="winOptLabel"> <widget class="QLabel" name="winOptLabel">
@ -1877,13 +1881,13 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>120</height> <height>180</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
<height>120</height> <height>180</height>
</size> </size>
</property> </property>
<property name="title"> <property name="title">
@ -1918,31 +1922,33 @@
<x>0</x> <x>0</x>
<y>40</y> <y>40</y>
<width>391</width> <width>391</width>
<height>21</height> <height>42</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Make direct I2P connections only to routers in specified Family:</string> <string>Make direct I2P connections only to
routers in specified Family:</string>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="labelTrustRouters"> <widget class="QLabel" name="labelTrustRouters">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>60</y> <y>82</y>
<width>661</width> <width>661</width>
<height>16</height> <height>42</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Make direct I2P connections only to routers specified here. Comma separated list of base64 identities:</string> <string>Make direct I2P connections only to routers specified here.
Comma separated list of base64 identities:</string>
</property> </property>
</widget> </widget>
<widget class="QLineEdit" name="lineEditTrustRouters"> <widget class="QLineEdit" name="lineEditTrustRouters">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>80</y> <y>124</y>
<width>661</width> <width>661</width>
<height>23</height> <height>23</height>
</rect> </rect>
@ -1952,7 +1958,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>100</y> <y>147</y>
<width>661</width> <width>661</width>
<height>21</height> <height>21</height>
</rect> </rect>

Loading…
Cancel
Save