33#include < QSettings>
44#include < QUrl>
55#include < QDebug>
6+ #include < QSerialPortInfo>
67
78#include " startup.h"
89#include " ui_startup.h"
@@ -19,16 +20,16 @@ Startup::Startup(QWidget *parent) :
1920 ui->remoteport ->setMaximumWidth (w+8 );
2021 QObject::connect (ui->startlocal , &QPushButton::clicked, this , &Startup::localPressed);
2122 QObject::connect (ui->startremote , &QPushButton::clicked, this , &Startup::remotePressed);
23+ foreach (QSerialPortInfo spinfo, QSerialPortInfo::availablePorts ()) {
2224#if defined(Q_OS_MACOS)
23- ui->serialport ->setText (QSettings ().value (" connection/serialport" , " /dev/cu.SLAB_USBtoUART" ).toString ());
24- #elif defined(Q_OS_WIN)
25- ui->serialport ->setText (QSettings ().value (" connection/serialport" , " COM1" ).toString ());
26- #else
27- ui->serialport ->setText (QSettings ().value (" connection/serialport" , " /dev/ttyUSB0" ).toString ());
25+ if (spinfo.portName ().startsWith (" tty" , Qt::CaseInsensitive))
26+ continue ;
2827#endif
29- ui->enableserver ->setChecked (QSettings ().value (" connection/startserver" , true ).toBool ());
28+ ui->serialport ->addItem (spinfo.systemLocation ());
29+ }
30+ // ui->enableserver->setChecked(QSettings().value("connection/startserver", true).toBool());
31+ ui->enableserver ->setChecked (true );
3032 QUrl server = QUrl::fromUserInput (QSettings ().value (" connection/remotehost" , " ws://localhost:1983" ).toString ());
31- qDebug () << server;
3233 ui->remotehost ->setText (server.host ());
3334 ui->remoteport ->setText (QString::number (server.port ()));
3435 ui->authKey ->setText (QSettings ().value (" connection/authKey" , " " ).toString ());
@@ -41,10 +42,7 @@ Startup::~Startup()
4142
4243void Startup::localPressed () {
4344
44- if (ui->serialport ->text ().length () == 0 ) {
45- QMessageBox::critical (this , tr (" Error" ), tr (" You Must Specify a Serial Port" ), QMessageBox::Ok);
46- }
47- this ->m_serialPort = ui->serialport ->text ();
45+ this ->m_serialPort = ui->serialport ->currentText ();
4846 this ->m_remote = false ;
4947 this ->m_startServer = ui->enableserver ->isChecked ();
5048 this ->setResult (DialogCode::Accepted);
@@ -53,6 +51,8 @@ void Startup::localPressed() {
5351void Startup::remotePressed () {
5452 if (ui->remotehost ->text ().length () == 0 ) {
5553 QMessageBox::critical (this , tr (" Error" ), tr (" You Must Specify a Remote Host" ), QMessageBox::Ok);
54+ this ->reject ();
55+ return ;
5656 }
5757 this ->m_remoteHost = ui->remotehost ->text ();
5858 this ->m_remotePort = ui->remoteport ->text ().toUInt ();
0 commit comments