Skip to content

Commit

Permalink
Add setSocketState.
Browse files Browse the repository at this point in the history
instead of capturing connected and disconnected signals we can use stateChanged signal and simplify a bit.
  • Loading branch information
mohsenD98 committed Oct 1, 2024
1 parent 6d99045 commit 3a4ee4d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
38 changes: 23 additions & 15 deletions src/core/positioning/egenioussreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ EgenioussReceiver::EgenioussReceiver( QObject *parent )
{
connect( mTcpSocket, &QTcpSocket::readyRead, this, &EgenioussReceiver::onReadyRead );
connect( mTcpSocket, &QTcpSocket::errorOccurred, this, &EgenioussReceiver::handleError );
connect( mTcpSocket, &QTcpSocket::connected, this, &EgenioussReceiver::connected );
connect( mTcpSocket, &QTcpSocket::disconnected, this, &EgenioussReceiver::disconnected );
connect( mTcpSocket, &QTcpSocket::stateChanged, this, &EgenioussReceiver::setSocketState );
setValid( true );
}

Expand All @@ -19,27 +18,36 @@ void EgenioussReceiver::handleConnectDevice()
mTcpSocket->connectToHost( mAddress, mPort, QTcpSocket::ReadWrite );
}

void EgenioussReceiver::connected()
{
mSocketState = QAbstractSocket::ConnectedState;
mSocketStateString = tr( "Successfully connected" );
emit socketStateChanged( mSocketState );
setValid( true );
}

void EgenioussReceiver::handleDisconnectDevice()
{
mTcpSocket->disconnectFromHost();
}

void EgenioussReceiver::disconnected()
void EgenioussReceiver::setSocketState()
{
if ( mTcpSocket->state() == QAbstractSocket::ConnectedState )
mSocketState = mTcpSocket ? mTcpSocket->state() : QAbstractSocket::UnconnectedState;
switch ( mSocketState )
{
mSocketState = QAbstractSocket::UnconnectedState;
mSocketStateString = tr( "Disconnected" );
emit socketStateChanged( mSocketState );
case QAbstractSocket::ConnectedState:
mSocketStateString = tr( "Successfully connected" );
case QAbstractSocket::UnconnectedState:
mSocketStateString = tr( "Disconnected" );
case QAbstractSocket::HostLookupState:
mSocketStateString = tr( "Looking up host" );
case QAbstractSocket::ConnectingState:
mSocketStateString = tr( "Connecting" );
case QAbstractSocket::BoundState:
mSocketStateString = tr( "Bound" );
case QAbstractSocket::ListeningState:
mSocketStateString = tr( "Listening" );
case QAbstractSocket::ClosingState:
mSocketStateString = tr( "Closing" );
default:
mSocketStateString = tr( "Unknown" );
}

emit socketStateChanged( mSocketState );
emit socketStateStringChanged( mSocketStateString );
}

QList<QPair<QString, QVariant>> EgenioussReceiver::details()
Expand Down
3 changes: 1 addition & 2 deletions src/core/positioning/egenioussreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EgenioussReceiver : public AbstractGnssReceiver
private:
void handleConnectDevice() override;
void handleDisconnectDevice() override;
void setSocketState();
QList<QPair<QString, QVariant>> details() override;

private slots:
Expand All @@ -24,8 +25,6 @@ class EgenioussReceiver : public AbstractGnssReceiver

private:
void processReceivedData();
void connected();
void disconnected();

private:
QTcpSocket *mTcpSocket = nullptr;
Expand Down
6 changes: 4 additions & 2 deletions src/qml/PositioningDeviceSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ Popup {
});
} else {
positioningDeviceTypeModel.remove(0, 1);
positioningDeviceModel.removeDevice("Egeniouss");
positioningDeviceComboBox.currentIndex = 0;
if (positioningDeviceModel.findIndexFromDeviceId("egeniouss:") !== -1) {
positioningDeviceModel.removeDevice("Egeniouss");
positioningDeviceComboBox.currentIndex = 0;
}
}
positioningDeviceType.model = positioningDeviceTypeModel;
}
Expand Down

0 comments on commit 3a4ee4d

Please sign in to comment.