diff --git a/commhandler.cpp b/commhandler.cpp index 75a8c43..9b02952 100644 --- a/commhandler.cpp +++ b/commhandler.cpp @@ -320,7 +320,7 @@ void commHandler::openPort() qInfo(logSerial()) << "Could not open serial port " << portName << " , please restart."; isConnected = false; serialError = true; - emit havePortError(errorType(portName, "Could not open port. Please restart.")); + emit havePortError(errorType(true, portName, "Could not open port. Please restart.")); return; } } diff --git a/wfmain.cpp b/wfmain.cpp index e0710a4..ba32172 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -677,6 +677,7 @@ void wfmain::receiveFoundRigID(rigCapabilities rigCaps) void wfmain::receivePortError(errorType err) { if (err.alert) { + connectionHandler(false); // Force disconnect QMessageBox::critical(this, err.device, err.message, QMessageBox::Ok); } else @@ -5273,26 +5274,14 @@ void wfmain::on_connectBtn_clicked() { this->rigStatus->setText(""); // Clear status - if (haveRigCaps) { - emit sendCloseComm(); - ui->connectBtn->setText("Connect to Radio"); - ui->audioSystemCombo->setEnabled(true); - ui->audioSystemServerCombo->setEnabled(true); - haveRigCaps = false; - rigName->setText("NONE"); + if (ui->connectBtn->text() == "Connect to Radio") { + connectionHandler(true); } - else + else { - emit sendCloseComm(); // Just in case there is a failed connection open. - if (ui->connectBtn->text() != "Cancel connection") { - openRig(); - } - else { - ui->connectBtn->setText("Connect to Radio"); - ui->audioSystemCombo->setEnabled(true); - ui->audioSystemServerCombo->setEnabled(true); - } + connectionHandler(false); } + ui->connectBtn->clearFocus(); } @@ -7681,3 +7670,28 @@ void wfmain::changePollTiming(int timing_ms, bool setUI) ui->pollTimeMsSpin->blockSignals(false); } } + +void wfmain::connectionHandler(bool connect) +{ + + if (!connect) { + emit sendCloseComm(); + ui->connectBtn->setText("Connect to Radio"); + ui->audioSystemCombo->setEnabled(true); + ui->audioSystemServerCombo->setEnabled(true); + haveRigCaps = false; + rigName->setText("NONE"); + } + else + { + emit sendCloseComm(); // Just in case there is a failed connection open. + if (ui->connectBtn->text() != "Cancel connection") { + openRig(); + } + else { + ui->connectBtn->setText("Connect to Radio"); + ui->audioSystemCombo->setEnabled(true); + ui->audioSystemServerCombo->setEnabled(true); + } + } +} diff --git a/wfmain.h b/wfmain.h index a1397bf..dd81ecc 100644 --- a/wfmain.h +++ b/wfmain.h @@ -985,6 +985,8 @@ private: void changeMode(mode_kind mode); void changeMode(mode_kind mode, bool dataOn); + void connectionHandler(bool connect); + cmds meterKindToMeterCommand(meterKind m); int oldFreqDialVal;