Ejemplo n.º 1
0
SmtpClient::SmtpClient(const QString & host, int port, ConnectionType ct) :
    name("localhost"),
    authMethod(AuthPlain),
    connectionTimeout(5000),
    responseTimeout(5000)
{
    if (ct == TcpConnection)
        this->useSsl = false;
    else if (ct == SslConnection)
        this->useSsl = true;

    if (useSsl == false)
        socket = new QTcpSocket(this);
    else
        socket = new QSslSocket(this);

    this->host = host;
    this->port = port;

    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(socketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(readyRead()),
            this, SLOT(socketReadyRead()));
}
// Constructs an unconnected PeerWire client and starts the connect timer.
PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
    : QTcpSocket(parent), pendingBlockSizes(0),
      pwState(ChokingPeer | ChokedByPeer), receivedHandShake(false), gotPeerId(false),
      sentHandShake(false), nextPacketLength(-1), pendingRequestTimer(0), invalidateTimeout(false),
      keepAliveTimer(0), torrentPeer(0)
{
    memset(uploadSpeedData, 0, sizeof(uploadSpeedData));
    memset(downloadSpeedData, 0, sizeof(downloadSpeedData));

    transferSpeedTimer = startTimer(RateControlTimerDelay);
    timeoutTimer = startTimer(ConnectTimeout);
    peerIdString = peerId;

    connect(this, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer()));
    connect(this, SIGNAL(connected()), this, SIGNAL(readyToTransfer()));

    connect(&socket, SIGNAL(connected()),
            this, SIGNAL(connected()));
    connect(&socket, SIGNAL(readyRead()),
            this, SIGNAL(readyRead()));
    connect(&socket, SIGNAL(disconnected()),
            this, SIGNAL(disconnected()));
    connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SIGNAL(error(QAbstractSocket::SocketError)));
    connect(&socket, SIGNAL(bytesWritten(qint64)),
            this, SIGNAL(bytesWritten(qint64)));
    connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));

}
Ejemplo n.º 3
0
void ClientSyncer::connectToCore(const QVariantMap &conn) {
  resetConnection();
  coreConnectionInfo = conn;

  if(conn["Host"].toString().isEmpty()) {
    emit connectionError(tr("No Host to connect to specified."));
    return;
  }

  Q_ASSERT(!_socket);
#ifdef HAVE_SSL
  QSslSocket *sock = new QSslSocket(Client::instance());
#else
  if(conn["useSsl"].toBool()) {
    emit connectionError(tr("<b>This client is built without SSL Support!</b><br />Disable the usage of SSL in the account settings."));
    return;
  }
  QTcpSocket *sock = new QTcpSocket(Client::instance());
#endif

#ifndef QT_NO_NETWORKPROXY
  if(conn.contains("useProxy") && conn["useProxy"].toBool()) {
    QNetworkProxy proxy((QNetworkProxy::ProxyType)conn["proxyType"].toInt(), conn["proxyHost"].toString(), conn["proxyPort"].toUInt(), conn["proxyUser"].toString(), conn["proxyPassword"].toString());
    sock->setProxy(proxy);
  }
#endif

  _socket = sock;
  connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData()));
  connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
  connect(sock, SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected()));
  connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(coreSocketError(QAbstractSocket::SocketError)));
  connect(sock, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
  sock->connectToHost(conn["Host"].toString(), conn["Port"].toUInt());
}
Ejemplo n.º 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    ipAddress(QString("192.168.1.101"))

{
    ui->setupUi(this);

    ui->disconnectPushButton->setEnabled(false);

    QObject::connect(ui->connectPushButton, SIGNAL(clicked(bool)),
                     this, SLOT(connectToServer()));
    QObject::connect(ui->disconnectPushButton, SIGNAL(clicked(bool)),
                     this, SLOT(disconnectFromServer()));

    socket = new QTcpSocket(this);

    QObject::connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                     this, SLOT(socketStateChanged()));

    QObject::connect(socket, SIGNAL(readyRead()),
                     this, SLOT(processIncommingMessage()));

    QObject::connect(ui->inputLineEdit, SIGNAL(returnPressed()),
                     this, SLOT(processOutgoingMessage()));

}
Ejemplo n.º 5
0
void AuthHandler::setSocket(QTcpSocket *socket)
{
    _socket = socket;
    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
}
Ejemplo n.º 6
0
void SslClient::establish(const QString& host, quint16 port)
{
    threadLock_  = new QMutex();
    threadEvent_ = new QWaitCondition();

    QMutexLocker blocked(threadLock_);
    host_ = host;
    port_ = port;

    start();
    threadEvent_->wait(threadLock_);

    if(ssl_.isNull() || running_ == false)
        Q_ASSERT_X(ssl_.isNull() || running_ == false, "SslClient::establish", "Cannot start SslClient's thread");

    connect(ssl_.data(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), 
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(encrypted()), 
            this, SLOT(socketEncrypted()), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(error(QAbstractSocket::SocketError)), 
            this, SLOT(socketError(QAbstractSocket::SocketError)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(sslErrors(QList<QSslError>)), 
            this, SLOT(sslErrors(QList<QSslError>)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(readyRead()), 
            this, SLOT(socketReadyRead()), Qt::DirectConnection);

    ConfigureForLMAX();
}
Ejemplo n.º 7
0
BtLocalDevice::BtLocalDevice(QObject *parent) :
    QObject(parent), securityFlags(QBluetooth::NoSecurity)
{
    localDevice = new QBluetoothLocalDevice(this);
    connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
            this, SIGNAL(error(QBluetoothLocalDevice::Error)));
    connect(localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
            this, SIGNAL(hostModeStateChanged()));
    connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)),
            this, SLOT(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
    connect(localDevice, SIGNAL(deviceConnected(QBluetoothAddress)),
            this, SLOT(connected(QBluetoothAddress)));
    connect(localDevice, SIGNAL(deviceDisconnected(QBluetoothAddress)),
            this, SLOT(disconnected(QBluetoothAddress)));
    connect(localDevice, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)),
            this, SLOT(pairingDisplayConfirmation(QBluetoothAddress,QString)));

    if (localDevice->isValid()) {
        deviceAgent = new QBluetoothDeviceDiscoveryAgent(this);
        connect(deviceAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
        connect(deviceAgent, SIGNAL(finished()),
                this, SLOT(discoveryFinished()));
        connect(deviceAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
                this, SLOT(discoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
        connect(deviceAgent, SIGNAL(canceled()),
                this, SLOT(discoveryCanceled()));

        serviceAgent = new QBluetoothServiceDiscoveryAgent(this);
        connect(serviceAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
                this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
        connect(serviceAgent, SIGNAL(finished()),
                this, SLOT(serviceDiscoveryFinished()));
        connect(serviceAgent, SIGNAL(canceled()),
                this, SLOT(serviceDiscoveryCanceled()));
        connect(serviceAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
                this, SLOT(serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error)));

        socket = new QBluetoothSocket(SOCKET_PROTOCOL, this);
        connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)),
                this, SLOT(socketStateChanged(QBluetoothSocket::SocketState)));
        connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)),
                this, SLOT(socketError(QBluetoothSocket::SocketError)));
        connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
        connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
        connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
        setSecFlags(socket->preferredSecurityFlags());

        server = new QBluetoothServer(SOCKET_PROTOCOL, this);
        connect(server, SIGNAL(newConnection()), this, SLOT(serverNewConnection()));
        connect(server, SIGNAL(error(QBluetoothServer::Error)),
                this, SLOT(serverError(QBluetoothServer::Error)));
    } else {
        deviceAgent = 0;
        serviceAgent = 0;
        socket = 0;
        server = 0;
    }
}
Ejemplo n.º 8
0
void Client::onConnectToServer(QHostAddress address, qint16 port, QString name)
{
	ClientRoom* newClientRoom = new ClientRoom(name, address, port);

	connect(newClientRoom->getSocket(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
	connect(newClientRoom->getSocket(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), newClientRoom, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
	connect(newClientRoom, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)), this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
	connect(newClientRoom, SIGNAL(sendTypedMessage(QString)), this, SLOT(onSendTypedMessage(QString)));
	newClientRoom->connect();
}
Ejemplo n.º 9
0
Client::Client(chatdialog *chat, QObject  *parent)
    : QObject(parent)
{
    chatDialog = chat;
    socket = new QTcpSocket(this);
    socket->connectToHost("127.0.0.1", 49998);
    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                   this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(readyRead()),
                   this, SLOT(socketReadyRead()));
}
Ejemplo n.º 10
0
 Client::Client(QString userId, QObject * parent) :
    QObject(parent),
    m_user_id(userId),
    m_state(Client::Disconnected)
 {
    connect(&m_socket, SIGNAL(connected()), this, SLOT(authenticate()));
    connect(&m_socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
    connect(&m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
          this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
          this, SLOT(socketError(QAbstractSocket::SocketError)));
 }
Ejemplo n.º 11
0
void Session::openSession(const QString &host, quint16 port, const QString &password)
{
	closeSession();
	setState(ConnectingState);
	m_host = host;
	m_port = port;
	m_password = password;
	m_socket = new Socket;
	connect(m_socket, SIGNAL(stateChanged(Socket::State)), SLOT(socketStateChanged(Socket::State)));
	connect(m_socket, SIGNAL(dataRecived(const QByteArray &)), SLOT(processData(const QByteArray &)));
	m_socket->connectToBoinc(m_host, m_port);
}
Ejemplo n.º 12
0
void SslClient::sslErrors(const QList<QSslError>& errors)
{
    Q_UNUSED(errors);

    ssl_->ignoreSslErrors();
    QAbstractSocket::SocketState st = ssl_->state();
    if( st != QAbstractSocket::ConnectedState )
    {
        socketStateChanged(ssl_->state());
        if( st == QAbstractSocket::ClosingState )
            handler_->onStateChanged(EstablishWarnState);
    }
}
Ejemplo n.º 13
0
DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, quint16 controlPort) :
    _ddeProcess(NULL),
    _ddeStopping(false),
    _host(host),
    _serverPort(serverPort),
    _controlPort(controlPort),
    _lastReceiveTimestamp(0),
    _reset(false),
    _leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
    _rightBlinkIndex(1),
    _leftEyeOpenIndex(8),
    _rightEyeOpenIndex(9),
    _browDownLeftIndex(14),
    _browDownRightIndex(15),
    _browUpCenterIndex(16),
    _browUpLeftIndex(17),
    _browUpRightIndex(18),
    _mouthSmileLeftIndex(28),
    _mouthSmileRightIndex(29),
    _jawOpenIndex(21),
    _lastMessageReceived(0),
    _averageMessageTime(STARTING_DDE_MESSAGE_TIME),
    _lastHeadTranslation(glm::vec3(0.0f)),
    _filteredHeadTranslation(glm::vec3(0.0f)),
    _lastBrowUp(0.0f),
    _filteredBrowUp(0.0f),
    _lastEyeBlinks(),
    _filteredEyeBlinks(),
    _lastEyeCoefficients(),
    _eyeClosingThreshold("ddeEyeClosingThreshold", DEFAULT_DDE_EYE_CLOSING_THRESHOLD),
    _isCalibrating(false),
    _calibrationCount(0),
    _calibrationValues(),
    _calibrationBillboard(NULL),
    _calibrationBillboardID(0),
    _calibrationMessage(QString()),
    _isCalibrated(false)
{
    _coefficients.resize(NUM_FACESHIFT_BLENDSHAPES);
    _blendshapeCoefficients.resize(NUM_FACESHIFT_BLENDSHAPES);
    _coefficientAverages.resize(NUM_FACESHIFT_BLENDSHAPES);
    _calibrationValues.resize(NUM_FACESHIFT_BLENDSHAPES);

    _eyeStates[0] = EYE_UNCONTROLLED;
    _eyeStates[1] = EYE_UNCONTROLLED;

    connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
    connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError)));
    connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), 
        SLOT(socketStateChanged(QAbstractSocket::SocketState)));
}
Ejemplo n.º 14
0
void SslClient::secureConnect()
{
    if (!socket) {
        socket = new QSslSocket(this);
        connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
        connect(socket, SIGNAL(encrypted()),
                this, SLOT(socketEncrypted()));
        connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
                this, SLOT(sslErrors(QList<QSslError>)));
        connect(socket, SIGNAL(readyRead()),
                this, SLOT(socketReadyRead()));
    }

    socket->connectToHostEncrypted(form->hostNameEdit->text(), form->portBox->value());
    updateEnabledState();
}
Ejemplo n.º 15
0
void SslClient::sslErrors(const QList<QSslError> &errors)
{
    // Assemble the error message, ...
    QStringList messages;
    foreach (const QSslError &error, errors)
        messages << error.errorString();

    // ... make sure the CertificateInfoControl knows about the certificate chain, ...
    emit certificateChainChanged(m_socket->peerCertificateChain());

    // ... and show the SSL error dialog.
    m_sslErrorControl->exec(messages.join("\n"));

    // If the socket has been disconnected (while we have shown the SSL error dialog) we have to update the state
    if (m_socket && (m_socket->state() != QAbstractSocket::ConnectedState))
        socketStateChanged(m_socket->state());
}
Ejemplo n.º 16
0
SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) :
    name("localhost"),
    authMethod(AuthPlain),
    connectionTimeout(5000),
    responseTimeout(5000)
{
    setConnectionType(connectionType);

    this->host = host;
    this->port = port;

    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(socketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(readyRead()),
            this, SLOT(socketReadyRead()));
}
Ejemplo n.º 17
0
void SslClient::setupSecureSocket()
{
    if (socket)
        return;

    socket = new QSslSocket(this);

    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(encrypted()),
            this, SLOT(socketEncrypted()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(socketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
            this, SLOT(sslErrors(QList<QSslError>)));
    connect(socket, SIGNAL(readyRead()),
            this, SLOT(socketReadyRead()));

}
Ejemplo n.º 18
0
//! [1]
void SslClient::secureConnect()
{
    if (!m_socket) {
        // Create a new SSL socket and connect against its signals to receive notifications about state changes
        m_socket = new QSslSocket(this);
        connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
        connect(m_socket, SIGNAL(encrypted()),
                this, SLOT(socketEncrypted()));
        connect(m_socket, SIGNAL(sslErrors(QList<QSslError>)),
                this, SLOT(sslErrors(QList<QSslError>)));
        connect(m_socket, SIGNAL(readyRead()),
                this, SLOT(socketReadyRead()));
    }

    // Trigger the SSL-handshake
    m_socket->connectToHostEncrypted(m_hostName, m_port);

    updateEnabledState();
}
Ejemplo n.º 19
0
void CNetworkConnection::initializeSocket()
{
	m_pSocket->moveToThread(thread());
    m_pSocket->setReadBufferSize(m_nInputSize);
    connect(m_pSocket, SIGNAL(connected()),
            this, SIGNAL(connected()));
	connect(m_pSocket, SIGNAL(readyRead()),
			this, SIGNAL(readyRead()));
    connect(m_pSocket, SIGNAL(disconnected()),
            this, SIGNAL(disconnected()));
    connect(m_pSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SIGNAL(error(QAbstractSocket::SocketError)));
    connect(m_pSocket, SIGNAL(bytesWritten(qint64)),
            this, SIGNAL(bytesWritten(qint64)));
    connect(m_pSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
	connect(m_pSocket, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose()));
    setOpenMode(m_pSocket->openMode());
    setSocketState(m_pSocket->state());
}
Ejemplo n.º 20
0
void SslClient::sslErrors(const QList<QSslError> &errors)
{
    QDialog errorDialog(this);
    Ui_SslErrors ui;
    ui.setupUi(&errorDialog);
    connect(ui.certificateChainButton, &QPushButton::clicked,
            this, &SslClient::displayCertificateInfo);

    for (const auto &error : errors)
        ui.sslErrorList->addItem(error.errorString());

    executingDialog = true;
    if (errorDialog.exec() == QDialog::Accepted)
        socket->ignoreSslErrors();
    executingDialog = false;

    // did the socket state change?
    if (socket->state() != QAbstractSocket::ConnectedState)
        socketStateChanged(socket->state());
}
Ejemplo n.º 21
0
void QgsAuthSslImportDialog::secureConnect()
{
  if ( leServer->text().isEmpty() )
  {
    return;
  }

  leServer->setStyleSheet( QLatin1String( "" ) );
  clearStatusCertificateConfig();

  if ( !mSocket )
  {
    mSocket = new QSslSocket( this );
    connect( mSocket, SIGNAL( stateChanged( QAbstractSocket::SocketState ) ),
             this, SLOT( socketStateChanged( QAbstractSocket::SocketState ) ) );
    connect( mSocket, SIGNAL( connected() ),
             this, SLOT( socketConnected() ) );
    connect( mSocket, SIGNAL( disconnected() ),
             this, SLOT( socketDisconnected() ) );
    connect( mSocket, SIGNAL( encrypted() ),
             this, SLOT( socketEncrypted() ) );
    connect( mSocket, SIGNAL( error( QAbstractSocket::SocketError ) ),
             this, SLOT( socketError( QAbstractSocket::SocketError ) ) );
    connect( mSocket, SIGNAL( sslErrors( QList<QSslError> ) ),
             this, SLOT( sslErrors( QList<QSslError> ) ) );
    connect( mSocket, SIGNAL( readyRead() ),
             this, SLOT( socketReadyRead() ) );
  }

  mSocket->setCaCertificates( mTrustedCAs );

  if ( !mTimer )
  {
    mTimer = new QTimer( this );
    connect( mTimer, SIGNAL( timeout() ), this, SLOT( destroySocket() ) );
  }
  mTimer->start( spinbxTimeout->value() * 1000 );

  mSocket->connectToHost( leServer->text(), spinbxPort->value() );
  updateEnabledState();
}
Ejemplo n.º 22
0
Client::Client(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::Client)
{
	ui->setupUi(this);

	defaultPseudo = QString("user%1").arg(qrand() % 9000 + 1000);
	ui->pseudoLineEdit->setPlaceholderText(defaultPseudo);

    wsSocket = new QtWebsocket::QWsSocket(this, NULL, QtWebsocket::WS_V13);

	socketStateChanged(wsSocket->state());

	QObject::connect(ui->sendButton, SIGNAL(pressed()), this, SLOT(sendMessage()));
	QObject::connect(ui->textLineEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
	QObject::connect(ui->connectButton, SIGNAL(pressed()), this, SLOT(connectSocket()));
	QObject::connect(ui->disconnectButton, SIGNAL(pressed()), this, SLOT(disconnectSocket()));
	QObject::connect(wsSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
	QObject::connect(wsSocket, SIGNAL(frameReceived(QString)), this, SLOT(displayMessage(QString)));
	QObject::connect(wsSocket, SIGNAL(connected()), this, SLOT(socketConnected()));
	QObject::connect(wsSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(wsSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(displaySslErrors(const QList<QSslError>&)));
}
Ejemplo n.º 23
0
void SslClient::sslErrors(const QList<QSslError> &errors)
{
    QDialog errorDialog(this);
    Ui_SslErrors ui;
    ui.setupUi(&errorDialog);
    connect(ui.certificateChainButton, SIGNAL(clicked()),
            this, SLOT(displayCertificateInfo()));

    foreach (const QSslError &error, errors)
        ui.sslErrorList->addItem(error.errorString());

    executingDialog = true;
#ifdef Q_OS_SYMBIAN
    errorDialog.showMaximized();
#endif
    if (errorDialog.exec() == QDialog::Accepted)
        socket->ignoreSslErrors();
    executingDialog = false;

    // did the socket state change?
    if (socket->state() != QAbstractSocket::ConnectedState)
        socketStateChanged(socket->state());
}
Ejemplo n.º 24
0
DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, quint16 controlPort) :
    _ddeProcess(NULL),
    _ddeStopping(false),
    _host(host),
    _serverPort(serverPort),
    _controlPort(controlPort),
    _lastReceiveTimestamp(0),
    _reset(false),
    _leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
    _rightBlinkIndex(1),
    _leftEyeOpenIndex(8),
    _rightEyeOpenIndex(9),
    _browDownLeftIndex(14),
    _browDownRightIndex(15),
    _browUpCenterIndex(16),
    _browUpLeftIndex(17),
    _browUpRightIndex(18),
    _mouthSmileLeftIndex(28),
    _mouthSmileRightIndex(29),
    _jawOpenIndex(21),
    _lastMessageReceived(0),
    _averageMessageTime(STARTING_DDE_MESSAGE_TIME),
    _lastHeadTranslation(glm::vec3(0.0f)),
    _filteredHeadTranslation(glm::vec3(0.0f)),
    _lastLeftEyeBlink(0.0f),
    _filteredLeftEyeBlink(0.0f),
    _lastRightEyeBlink(0.0f),
    _filteredRightEyeBlink(0.0f)
{
    _coefficients.resize(NUM_FACESHIFT_BLENDSHAPES);

    _blendshapeCoefficients.resize(NUM_FACESHIFT_BLENDSHAPES);
    
    connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
    connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError)));
    connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socketStateChanged(QAbstractSocket::SocketState)));
}
Ejemplo n.º 25
0
DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 port) :
_lastReceiveTimestamp(0),
_reset(false),
_leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
_rightBlinkIndex(1),
_leftEyeOpenIndex(8),
_rightEyeOpenIndex(9),
_browDownLeftIndex(14),
_browDownRightIndex(15),
_browUpCenterIndex(16),
_browUpLeftIndex(17),
_browUpRightIndex(18),
_mouthSmileLeftIndex(28),
_mouthSmileRightIndex(29),
_jawOpenIndex(21)
{
    _blendshapeCoefficients.resize(NUM_EXPRESSION);
    
    connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
    connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketErrorOccurred(QAbstractSocket::SocketError)));
    connect(&_udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
    
    bindTo(host, port);
}
Ejemplo n.º 26
0
/*!
 * \brief SimComm::SimComm creates an abstract object to communicate with V-REP. \n
 * This object does the actual communication via TCP sockets, and has the timer
 * to signal cache expiration.
 * \param port the TCP port to open.
 */
SimComm::SimComm(int port) :
    cache_timer(new QTimer()),
    socket(new QTcpSocket()),
    port(port),
    connected(false)
{
    this->cache_timer->setSingleShot(true);
    QObject::connect(this->cache_timer.get(), SIGNAL(timeout()), this, SIGNAL(cache_expired()));
    QObject::connect(this->socket.get(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
}
Ejemplo n.º 27
0
QTcpSocket *Server::getRemoteSocket()
{
    if (remote_server_socket && remote_server_socket->state()==QAbstractSocket::ConnectedState && remote_server_socket->isWritable()) {
        return remote_server_socket;
    }
    if (remote_server_socket) delete remote_server_socket;
    is_init_connection = true;
    remote_server_socket = new QTcpSocket();
    remote_server_socket->connectToHost(QHostAddress(remoteIPAddress), remote_port, QIODevice::ReadWrite);
    if (remote_server_socket->waitForConnected(5000)) {
        connect(remote_server_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
        connect(remote_server_socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
        connect(remote_server_socket, SIGNAL(readyRead()), this, SLOT(recieveData()));
        connect(remote_server_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
    } else {
        emit error(tr("Connect error: %1").arg(remote_server_socket->errorString()));
        delete remote_server_socket;
        remote_server_socket = NULL;
    }
    is_init_connection = false;
    if (!remote_server_socket) {
        connectionTimer->start();
    } else {
        connectionTimer->stop();
    }
    return remote_server_socket;
}
Ejemplo n.º 28
0
void Server::recieveConnection()
{
    if (is_init_connection) return;

    QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
    QString client_ip = clientConnection->peerAddress().toString();
    quint32 client_ip_int = clientConnection->peerAddress().toIPv4Address();

    emit write_message(tr("New connection from IP: %1").arg(client_ip));

    connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));

    if (client_ip_int == QHostAddress(remoteIPAddress).toIPv4Address() || is_config_mode) {
        if (remote_server_socket && clientConnection != remote_server_socket) {
            delete remote_server_socket;
        }
        remote_server_socket = clientConnection;
        connect(clientConnection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
        connect(clientConnection, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
        connect(clientConnection, SIGNAL(readyRead()), this, SLOT(recieveData()));
        connect(clientConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
    } else {
        clientConnection->abort();
    }
}
Ejemplo n.º 29
0
MainWindow::MainWindow(QString filename, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle(QApplication::applicationName()+" "+ QApplication::applicationVersion());
    //ui->lastValuesBox->hide();
    bytesRead=0;
    bytesWritten=0;

    lastValueDoubleClick=new DoubleClickEventFilter(this);
    ui->lastValuesBox->installEventFilter(lastValueDoubleClick);
    connect (lastValueDoubleClick,SIGNAL(doubleClicked()),this,SLOT(clearLastValues()));
    connect (lastValueDoubleClick,SIGNAL(doubleClicked()),this,SLOT(initLastValues()));

    appSettings=new QSettings(QSettings::IniFormat,QSettings::UserScope,QApplication::organizationName(),QApplication::applicationName(),this);

    data=new ExperimentData(this);
    dilatometerData=new DilatometerData(this);
    data->setDilatometerData(dilatometerData);

    experiment=new Experiment(&tcpClient,this);

    dilatometerPlot=NULL;

    plot=new Plot(this);
    plot->setExperimentData(data);
    plot->setAxisTitle(QwtPlot::xBottom,tr("t, sec"));

    ui->plotLayout->addWidget(plot);




    connect(ui->actionFullscreen,SIGNAL(triggered(bool)),this,SLOT(setFullscreen(bool)));
    connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close()));
    connect(ui->actionConnect_to,SIGNAL(triggered()),this,SLOT(connectTo()));
    connect(ui->actionDisconnect,SIGNAL(triggered()),this,SLOT(socketDisconnect()));
    connect(ui->actionViewData,SIGNAL(triggered()),this,SLOT(showDataViewWindow()));
    connect(ui->actionReplot,SIGNAL(triggered()),plot,SLOT(replot()));
    connect(ui->actionClear_plot,SIGNAL(triggered()),plot,SLOT(clear()));
    connect(ui->actionInitialize,SIGNAL(triggered()),plot,SLOT(initialize()));
    connect(ui->actionSelect_points,SIGNAL(toggled(bool)),plot,SLOT(selectPointsMode(bool)));
    connect(ui->actionZoom_to_extents,SIGNAL(triggered()),plot,SLOT(zoomExtents()));
    connect(ui->actionDraw_incremental,SIGNAL(triggered(bool)),plot,SLOT(setIncrementalDraw(bool)));
    connect(ui->actionOpen_file,SIGNAL(triggered()),SLOT(openFile()));
    connect(ui->actionSave_as,SIGNAL(triggered()),SLOT(saveFile()));
    connect(ui->actionMonitoring_interval,SIGNAL(triggered()),SLOT(setMonitoringInterval()));
    connect(ui->actionSetup,SIGNAL(triggered()),SLOT(showSetupCurvesDialog()));
    connect(ui->actionSet_interval,SIGNAL(triggered()),SLOT(setInterval()));
    connect(ui->actionControl,SIGNAL(triggered()),SLOT(viewExperimentControlDialog()));
    connect(ui->actionStart,SIGNAL(triggered(bool)),&tcpClient,SLOT(start(bool)));

    connect(ui->actionApproximate,SIGNAL(triggered()),SLOT(approximate()));
    connect(ui->actionShow_approximations,SIGNAL(triggered(bool)),plot,SLOT(showApproximationCurves(bool)));
    connect(ui->actionConfiguration,SIGNAL(triggered()),SLOT(showConfigurationDialog()));
    connect(ui->actionLast_calculation,SIGNAL(triggered()),SLOT(showCalculationLog()));
    connect(ui->actionDilatometry,SIGNAL(toggled(bool)),SLOT(showDilatometryPlot(bool)));
    connect(ui->actionZoom_yLeft_to_extents,SIGNAL(triggered()),SLOT(zoomYLeftToExtents()));
    connect(ui->actionAbout_Qt,SIGNAL(triggered()),QApplication::instance(),SLOT(aboutQt()));
    connect(ui->actionAbout,SIGNAL(triggered()),SLOT(showAbout()));
    connect(ui->actionSet_tolerance_alarm,SIGNAL(triggered()),plot,SLOT(setToleranceAlarm()));
    connect(ui->actionRemove_tolerance_alarm,SIGNAL(triggered()),plot,SLOT(removeToleranceAlarm()));
    connect(ui->actionView_tolerance,SIGNAL(triggered()),SLOT(showToleranceAlarmState()));

    plot->enableAutoZoom(ui->actionAuto_zoom->isChecked());
    connect(ui->actionAuto_zoom,SIGNAL(triggered(bool)),plot,SLOT(enableAutoZoom(bool)));


    //ui->actionDraw_incremental->trigger();

    connect(plot,SIGNAL(message(QString)),statusBar(),SLOT(showMessage(QString)));
    connect(ui->actionSelectT0,SIGNAL(toggled(bool)),plot,SLOT(selectT0(bool)));
    connect(plot,SIGNAL(T0Selected(bool)),ui->actionSelectT0,SLOT(trigger()));
    connect(plot,SIGNAL(T0Selected(bool)),ui->actionSelect_points,SLOT(setChecked(bool)));
    connect(plot,SIGNAL(toleranceAlarmSet(bool)),SLOT(toleranceAlarmStatusChange(bool)));
    connect(plot,SIGNAL(curvePointClicked(QwtPlotCurve*,int)),this,SLOT(updateSelectedValue(QwtPlotCurve*,int)));

    connect(&tcpClient,SIGNAL(connected()),this,SLOT(socketConnectedToServer()));
    connect(&tcpClient,SIGNAL(disconnected()),this,SLOT(socketDisconnectedFromServer()));
    connect(&tcpClient,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(&tcpClient,SIGNAL(dataLine(QByteArray&)),data,SLOT(parseLine(QByteArray&)));
    connect(&tcpClient,SIGNAL(initialData()),plot,SLOT(clear()));
    connect(&tcpClient,SIGNAL(initialData()),data,SLOT(resetData()));
    connect(&tcpClient,SIGNAL(serverStatus(bool)),ui->actionStart,SLOT(setChecked(bool)));

    connect(&tcpClient,SIGNAL(bytesWritten(int)),this,SLOT(appendBytesWritten(int)));
    connect(&tcpClient,SIGNAL(bytesRead(int)),this,SLOT(appendBytesRead(int)));
    connect(&tcpClient,SIGNAL(serverInterval(int)),experiment,SLOT(setInterval(int)));


    connect(data,SIGNAL(initialized()),plot,SLOT(initialize()));
    connect(data,SIGNAL(initialized()),this,SLOT(initLastValues()));
    connect(data,SIGNAL(pointCount(int)),&pointCountLabel,SLOT(setNum(int)));
    connect(data,SIGNAL(pointCount(int)),plot,SLOT(drawLastPoint()));
    /** This connection will cause to plot VLine markers*/
    //connect(data,SIGNAL(marker(QPointF,int)),plot,SLOT(appendMarker(QPointF,int)));
    connect(data,SIGNAL(marker(int)),plot,SLOT(appendMarker(int)));
    connect(data,SIGNAL(pointCount(int)),this,SLOT(updateLastValues()));
    connect(data,SIGNAL(heaterPower(int)),this,SLOT(setHeaterPower(int)));


    connectionLabel.setText("*");
    connectionLabel.setToolTip(tr("Connection status:\nGreen - connected\nRed - disconnected"));
    connectionLabel.setStyleSheet("QLabel {color:red; font-weight:bold;}");
    pointCountLabel.setText("0");
    pointCountLabel.setToolTip(tr("Number of points"));
    bytesWrittenLabel.setText("0");
    bytesWrittenLabel.setToolTip("Bytes written to network");
    bytesReadLabel.setText("0");
    bytesReadLabel.setToolTip("Bytes read from network");

    ui->heaterPowerBar->setStyleSheet("QProgressBar::chunk {margin: 0px; width: 1px;}");

    ui->statusBar->addPermanentWidget(&bytesReadLabel);
    ui->statusBar->addPermanentWidget(&bytesWrittenLabel);
    ui->statusBar->addPermanentWidget(&pointCountLabel);
    ui->statusBar->addPermanentWidget(&connectionLabel);

    //if file was specified on startup - try open it
    if (!filename.isEmpty()) openFile(filename);


}
Ejemplo n.º 30
0
void Server::recieveConnection()
{
    QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
    connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));

    QString client_ip = clientConnection->peerAddress().toString();
    quint32 client_ip_int = clientConnection->peerAddress().toIPv4Address();

    emit write_message(tr("New connection from IP: %1").arg(client_ip));

    if (sockets->contains(client_ip_int)) {
        QTcpSocket *oldClientConnection = (QTcpSocket*) sockets->value(client_ip_int);
        if (oldClientConnection && oldClientConnection->state() != QAbstractSocket::UnconnectedState) {
            oldClientConnection->disconnectFromHost();
        }
        sockets->remove(client_ip_int);
    }

    sockets->insert(client_ip_int, clientConnection);

    connect(clientConnection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    connect(clientConnection, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
    connect(clientConnection, SIGNAL(readyRead()), this, SLOT(recieveData()));
    connect(clientConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
}