Skip to content

Commit

Permalink
Add more type for raw socket
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Jan 15, 2025
1 parent 0452c61 commit 0c48be0
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 25 deletions.
20 changes: 12 additions & 8 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ CentralWidget::CentralWidget(QString dir, StartupUIMode mode, QLocale lang, bool
} else if(type == "localshell") {
startLocalShellSession(findCurrentFocusGroup(),-1);
} else if(type == "raw") {
startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port.toInt());
startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port.toInt(),0);
} else if(type == "namepipe") {
startNamePipeSession(findCurrentFocusGroup(),-1,hostname);
} else if(type == "ssh") {
Expand Down Expand Up @@ -2571,7 +2571,7 @@ void CentralWidget::onPluginRequestLocalShellConnect(QString command, QString wo
}

void CentralWidget::onPluginRequestRawSocketConnect(QString host, int port) {
startRawSocketSession(findCurrentFocusGroup(),-1,host,port);
startRawSocketSession(findCurrentFocusGroup(),-1,host,port,0);
}

void CentralWidget::onPluginRequestNamePipeConnect(QString namePipe) {
Expand Down Expand Up @@ -4120,7 +4120,7 @@ void CentralWidget::connectSessionFromSessionManager(QString name)
startLocalShellSession(findCurrentFocusGroup(),-1,data.LocalShellData.command,globalOptionsWindow->getNewTabWorkPath(),current_name);
break;
case QuickConnectWindow::Raw:
startRawSocketSession(findCurrentFocusGroup(),-1,data.RawData.hostname,data.RawData.port, current_name);
startRawSocketSession(findCurrentFocusGroup(),-1,data.RawData.hostname,data.RawData.port,data.RawData.mode,current_name);
break;
case QuickConnectWindow::NamePipe:
startNamePipeSession(findCurrentFocusGroup(),-1,data.NamePipeData.pipeName, current_name);
Expand Down Expand Up @@ -4247,7 +4247,7 @@ QString CentralWidget::startSerialSession(MainWidgetGroup *group, int groupIndex
return name;
}

QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, QString name)
QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, int mode, QString name)
{
SessionsWindow *sessionsWindow = new SessionsWindow(SessionsWindow::RawSocket,this);
setGlobalOptions(sessionsWindow);
Expand All @@ -4260,7 +4260,7 @@ QString CentralWidget::startRawSocketSession(MainWidgetGroup *group, int groupIn
checkSessionName(name);
}
sessionsWindow->setName(name);
sessionsWindow->startRawSocketSession(hostname,port);
sessionsWindow->startRawSocketSession(hostname,port,mode);
sessionList.push_back(sessionsWindow);
connect(sessionsWindow, &SessionsWindow::titleChanged, this, [=](int title,const QString& newTitle){
if(title == 0 || title == 2) {
Expand Down Expand Up @@ -4586,7 +4586,7 @@ void CentralWidget::startSession(MainWidgetGroup *group, int groupIndex, QuickCo
} else if(data.type == QuickConnectWindow::Raw) {
QString name = data.RawData.hostname;
if(data.openInTab) {
name = startRawSocketSession(group,groupIndex,name,data.RawData.port);
name = startRawSocketSession(group,groupIndex,name,data.RawData.port,data.RawData.mode);
} else {
checkSessionName(name);
}
Expand Down Expand Up @@ -4837,6 +4837,7 @@ void CentralWidget::sessionWindow2InfoData(SessionsWindow *sessionsWindow, Quick
case QuickConnectWindow::Raw:
data.RawData.hostname = sessionsWindow->getHostname();
data.RawData.port = sessionsWindow->getPort();
data.RawData.mode = sessionsWindow->getRawMode();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = sessionsWindow->getPipeName();
Expand Down Expand Up @@ -4883,6 +4884,7 @@ int CentralWidget::setting2InfoData(GlobalSetting *settings, QuickConnectWindow:
case QuickConnectWindow::Raw:
data.RawData.hostname = settings->value("hostname").toString();
data.RawData.port = settings->value("port").toInt();
data.RawData.mode = settings->value("mode").toInt();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = settings->value("pipeName").toString();
Expand Down Expand Up @@ -4941,6 +4943,7 @@ void CentralWidget::infoData2Setting(GlobalSetting *settings,const QuickConnectW
case QuickConnectWindow::Raw:
settings->setValue("hostname",data.RawData.hostname);
settings->setValue("port",data.RawData.port);
settings->setValue("mode",data.RawData.mode);
break;
case QuickConnectWindow::NamePipe:
settings->setValue("pipeName",data.NamePipeData.pipeName);
Expand Down Expand Up @@ -5380,10 +5383,11 @@ int CentralWidget::se_sessionConnect(const QString &cmd,int id) {
return 0;
}
} else if(args[i] == "-raw") {
if(i+2 < args.size()) {
if(i+3 < args.size()) {
QString hostname = args[i+1];
quint16 port = args[i+2].toUShort();
startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port);
int mode = args[i+3].toInt();
startRawSocketSession(findCurrentFocusGroup(),-1,hostname,port,mode);
return 0;
}
} else if(args[i] == "-namepipe") {
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class CentralWidget : public QMainWindow
#if defined(Q_OS_WIN)
QString startWslSession(MainWidgetGroup *group, int groupIndex, const QString &command = QString(), const QString &workingDirectory = QDir::homePath(), QString name = QString());
#endif
QString startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, QString name = QString());
QString startRawSocketSession(MainWidgetGroup *group, int groupIndex, QString hostname, quint16 port, int mode, QString name = QString());
QString startNamePipeSession(MainWidgetGroup *group, int groupIndex, QString namePipe, QString name = QString());
QString startSSH2Session(MainWidgetGroup *group, int groupIndex,
QString hostname, quint16 port, QString username, QString password, QString name = QString());
Expand Down
14 changes: 13 additions & 1 deletion src/quickconnectwindow/quickconnectwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
case Telnet: {
ui->labelHostname->setText(tr("Hostname"));
ui->labelPort->setText(tr("Port"));
ui->labelWebSocket->setText(tr("WebSocket"));
ui->comboBoxHostname->setVisible(false);
ui->pushButtonRefresh->setVisible(false);
ui->lineEditHostname->setVisible(true);
Expand All @@ -88,6 +89,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(true);
ui->comboBoxWebSocket->setVisible(true);
ui->comboBoxRawMode->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
ui->labelParity->setVisible(false);
Expand Down Expand Up @@ -121,6 +123,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(true);
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip(tr("e.g. 110, 300, 600, 1200, 2400, \n4800, 9600, 14400, 19200, 38400, \n56000, 57600, 115200, 128000, 256000, \n460800, 921600"));
ui->comboBoxRawMode->setVisible(false);
ui->labelWebSocket->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(true);
Expand Down Expand Up @@ -164,6 +167,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setVisible(false);
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(false);
ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
Expand All @@ -180,6 +184,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
case Raw: {
ui->labelHostname->setText(tr("Hostname"));
ui->labelPort->setText(tr("Port"));
ui->labelWebSocket->setText(tr("mode"));
ui->comboBoxHostname->setVisible(false);
ui->pushButtonRefresh->setVisible(false);
ui->lineEditHostname->setVisible(true);
Expand All @@ -190,7 +195,8 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(true);
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(false);
ui->labelWebSocket->setVisible(true);
ui->comboBoxRawMode->setVisible(true);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
Expand All @@ -205,6 +211,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setMinimum(0);
ui->spinBoxPort->setMaximum(65535);
ui->spinBoxPort->setValue(8080);
ui->comboBoxRawMode->setCurrentIndex(0);
break;
}
case NamePipe:{
Expand All @@ -219,6 +226,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelPort->setVisible(false);
ui->spinBoxPort->setVisible(false);
ui->spinBoxPort->setToolTip("");
ui->comboBoxRawMode->setVisible(false);
ui->labelWebSocket->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
Expand Down Expand Up @@ -251,6 +259,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->spinBoxPort->setVisible(true);
ui->spinBoxPort->setToolTip("");
ui->labelWebSocket->setVisible(false);
ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
Expand Down Expand Up @@ -281,6 +290,7 @@ void QuickConnectWindow::comboBoxProtocolChanged(int index)
ui->labelWebSocket->setVisible(false);
ui->labelUsername->setVisible(false);
ui->lineEditUsername->setVisible(false);
ui->comboBoxRawMode->setVisible(false);
ui->comboBoxWebSocket->setVisible(false);
ui->labelDataBits->setVisible(false);
ui->comboBoxDataBits->setVisible(false);
Expand Down Expand Up @@ -332,6 +342,7 @@ void QuickConnectWindow::buttonBoxAccepted(void)
case Raw:
data.RawData.hostname = ui->lineEditHostname->text();
data.RawData.port = ui->spinBoxPort->value();
data.RawData.mode = ui->comboBoxRawMode->currentIndex();
emit this->sendQuickConnectData(data);
break;
case NamePipe:
Expand Down Expand Up @@ -399,6 +410,7 @@ void QuickConnectWindow::setQuickConnectData(QuickConnectData data)
case Raw:
ui->lineEditHostname->setText(data.RawData.hostname);
ui->spinBoxPort->setValue(data.RawData.port);
ui->comboBoxRawMode->setCurrentIndex(data.RawData.mode);
break;
case NamePipe:
ui->lineEditHostname->setText(data.NamePipeData.pipeName);
Expand Down
1 change: 1 addition & 0 deletions src/quickconnectwindow/quickconnectwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class QuickConnectWindow : public QDialog
struct {
QString hostname;
int port;
int mode;
}RawData;
struct {
QString pipeName;
Expand Down
30 changes: 27 additions & 3 deletions src/quickconnectwindow/quickconnectwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxRawMode">
<item>
<property name="text">
<string>TCP Client</string>
</property>
</item>
<item>
<property name="text">
<string>TCP Server</string>
</property>
</item>
<item>
<property name="text">
<string>UDP Send</string>
</property>
</item>
<item>
<property name="text">
<string>UDP Recv</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -332,7 +356,7 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -372,10 +396,10 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions src/scriptengine/pyrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ PyRun::PyRun(QObject *parent)
resultList->append(QString::number(centralWidget->se_sessionGetLogging(id)));
} else if (cmd == "sessionConnect") {
int id = cmdList.at(1).toInt();
QString cmd = cmdList.at(2);
centralWidget->se_sessionConnect(cmd,id);
QString ccmd = cmdList.at(2);
centralWidget->se_sessionConnect(ccmd,id);
} else if (cmd == "sessionDisconnect") {
int id = cmdList.at(1).toInt();
centralWidget->se_sessionDisconnect(id);
Expand Down
1 change: 1 addition & 0 deletions src/sessionoptions/sessionoptionsrawproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SessionOptionsRawProperties::SessionOptionsRawProperties(QWidget *parent) :
ui(new Ui::SessionOptionsRawProperties)
{
ui->setupUi(this);
ui->lineEditReadOnlyRawMode->setVisible(true);
}

SessionOptionsRawProperties::~SessionOptionsRawProperties()
Expand Down
44 changes: 42 additions & 2 deletions src/sessionoptions/sessionoptionsrawproperties.ui
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,55 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxRawMode">
<item>
<property name="text">
<string>TCP Client</string>
</property>
</item>
<item>
<property name="text">
<string>TCP Server</string>
</property>
</item>
<item>
<property name="text">
<string>UDP Send</string>
</property>
</item>
<item>
<property name="text">
<string>UDP Recv</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditReadOnlyRawMode"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down
3 changes: 3 additions & 0 deletions src/sessionoptions/sessionoptionswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void SessionOptionsWindow::setSessionProperties(QString name, QuickConnectWindow
case QuickConnectWindow::Raw:
sessionOptionsRawProperties->ui->lineEditHostname->setText(data.RawData.hostname);
sessionOptionsRawProperties->ui->spinBoxPort->setValue(data.RawData.port);
sessionOptionsRawProperties->ui->comboBoxRawMode->setCurrentIndex(data.RawData.mode);
break;
case QuickConnectWindow::NamePipe:
sessionOptionsNamePipeProperties->ui->lineEditPipeName->setText(data.NamePipeData.pipeName);
Expand Down Expand Up @@ -357,6 +358,7 @@ void SessionOptionsWindow::setReadOnly(bool enable) {

sessionOptionsRawProperties->ui->lineEditHostname->setReadOnly(enable);
sessionOptionsRawProperties->ui->spinBoxPort->setReadOnly(enable);
comboxSetReadOnly(sessionOptionsRawProperties->ui->comboBoxRawMode, sessionOptionsRawProperties->ui->lineEditReadOnlyRawMode);

sessionOptionsNamePipeProperties->ui->lineEditPipeName->setReadOnly(enable);

Expand Down Expand Up @@ -398,6 +400,7 @@ void SessionOptionsWindow::buttonBoxAccepted(void)
case QuickConnectWindow::Raw:
data.RawData.hostname = sessionOptionsRawProperties->ui->lineEditHostname->text();
data.RawData.port = sessionOptionsRawProperties->ui->spinBoxPort->value();
data.RawData.mode = sessionOptionsRawProperties->ui->comboBoxRawMode->currentIndex();
break;
case QuickConnectWindow::NamePipe:
data.NamePipeData.pipeName = sessionOptionsNamePipeProperties->ui->lineEditPipeName->text();
Expand Down
Loading

0 comments on commit 0c48be0

Please sign in to comment.