Пример #1
0
void SimondConnector::disconnectFromServer()
{
    emit status(tr("Disconnecting from server, please wait..."));
    emit connectionState(Disconnecting);
    timeoutTimer->stop();
    socket->abort();
    if (socket->state() == QAbstractSocket::UnconnectedState) {
        emit connectionState(Unconnected);
        emit status(tr("Idle"));
    } else
        socket->disconnectFromHost();
}
Пример #2
0
SimondConnector::SimondConnector(QObject *parent) :
    QObject(parent), state(Unconnected),
    socket(new QSslSocket(this)),
    timeoutTimer(new QTimer(this)),
    response(new QDataStream(socket)),
    mic(new SoundInput(SOUND_CHANNELS, SOUND_SAMPLERATE, this)),
    passThroughSound(false)
{
    connect(this, SIGNAL(connectionState(ConnectionState)), this, SLOT(setCurrentState(ConnectionState)));
    connect(socket, SIGNAL(readyRead()), this, SLOT(messageReceived()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError()));
    connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(socketError()));
    connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
    connect(socket, SIGNAL(encrypted()), this, SLOT(connectionEstablished()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(connectionLost()));

    connect(mic, SIGNAL(error(QString)), this, SIGNAL(error(QString)));
    connect(mic, SIGNAL(microphoneLevel(int,int,int)), this, SIGNAL(microphoneLevel(int,int,int)));
    connect(mic, SIGNAL(listening()), this, SLOT(startRecording()));
    connect(mic, SIGNAL(complete()), this, SLOT(commitRecording()));
    connect(mic, SIGNAL(readyRead()), this, SLOT(soundDataAvailable()));

    connect(timeoutTimer, SIGNAL(timeout()), this, SLOT(timeoutReached()));
    timeoutTimer->setSingleShot(true);
    timeoutTimer->setInterval(SOCKET_TIMEOUT);
}
Пример #3
0
int main(int argc, char *argv[])
{
    QCoreApplication::addLibraryPath("app/native/plugins");
    QApplication app(argc, argv);

    SimondConnector connector;
    QMLSimoneView view;

    QObject::connect(&view, SIGNAL(connectToServer()), &connector, SLOT(connectToServer()));
    QObject::connect(&view, SIGNAL(disconnectFromServer()), &connector, SLOT(disconnectFromServer()));
    QObject::connect(&view, SIGNAL(startRecording()), &connector, SLOT(startRecording()));
    QObject::connect(&view, SIGNAL(commitRecording()), &connector, SLOT(commitRecording()));
    QObject::connect(&view, SIGNAL(configurationChanged()), &connector, SLOT(configurationChanged()));

    QObject::connect(&connector, SIGNAL(connectionState(ConnectionState)), &view, SLOT(displayConnectionState(ConnectionState)));
    QObject::connect(&connector, SIGNAL(status(QString)), &view, SLOT(displayStatus(QString)));
    QObject::connect(&connector, SIGNAL(error(QString)), &view, SLOT(displayError(QString)));
    QObject::connect(&connector, SIGNAL(listening()), &view, SLOT(displayListening()));
    QObject::connect(&connector, SIGNAL(recognizing()), &view, SLOT(displayRecognizing()));
    QObject::connect(&connector, SIGNAL(microphoneLevel(int,int,int)), &view, SLOT(displayMicrophoneLevel(int,int,int)));
    QObject::connect(&connector, SIGNAL(recognized(RecognitionResultList)), &view, SLOT(recognized(RecognitionResultList)));

    view.show();
    connector.init();

    return app.exec();
}
Пример #4
0
QPixmap
TwitterAccount::icon() const
{
    if ( connectionState() == Connected )
        return m_onlinePixmap;
    return m_offlinePixmap;
}
Пример #5
0
void SimondConnector::timeoutReached()
{
    socket->abort();
    socket->close();
    emit connectionState(Unconnected);
    emit error(tr("Timeout connecting to server"));
    emit status(tr("Idle"));
}
Пример #6
0
void SimondConnector::connectionLost()
{
    timeoutTimer->stop();
    if (state != Disconnecting) {
        emit error(tr("Connection to server lost"));
    }
    emit connectionState(Unconnected);
    emit status(tr("Disconnected"));
}
Пример #7
0
void SimondConnector::connectionEstablished()
{
    qDebug() << "Connection established";
    timeoutTimer->stop();
    emit status(tr("Connected; Logging in..."));
    emit connectionState(ConnectedWaiting);

    login();
}
Пример #8
0
void SimondConnector::socketError()
{
    if (timeoutTimer->isActive())
      timeoutTimer->stop();

    QList<QSslError> errors = socket->sslErrors();
    if ((errors.count() == 1) && (errors[0].error() == QSslError::SelfSignedCertificate)) {
        //silently ignore self signed certificates for now
        socket->ignoreSslErrors();
        return;
    }
    QString errorMessage;
    if (!errors.isEmpty()) {
        for (int i=0; i < errors.count(); i++)
            errorMessage += errors[i].errorString()+'\n';
        errorMessage = errorMessage.trimmed();
    } else
        errorMessage = socket->errorString();

    emit error(tr("Failed to connect to server: ")+errorMessage);

    switch(socket->state()) {
    case QAbstractSocket::UnconnectedState:
        emit connectionState(Unconnected);
        break;
    case QAbstractSocket::HostLookupState:
    case QAbstractSocket::ConnectingState:
        emit connectionState(Connecting);
        break;
    case QAbstractSocket::ConnectedState:
    case QAbstractSocket::BoundState:
    case QAbstractSocket::ListeningState:
        emit connectionState(Connected);
        break;
    case QAbstractSocket::ClosingState:
        emit connectionState(Unconnected);
        break;
    }
    emit status(tr("Idle")); //clear current status after error
}
Пример #9
0
int main(int argc, char *argv[])
{
    QCoreApplication::addLibraryPath("app/native/plugins");
    QApplication app(argc, argv);

    bool voiceControlled = true;
    SimondConnector *connector;
    if (voiceControlled)
        connector = new SimondConnector;
    else
        connector = 0;

    Recomment recomment;
    QMLRecommentView view(&recomment, voiceControlled);

    if (voiceControlled) {
        QObject::connect(&view, SIGNAL(connectToServer()), connector, SLOT(connectToServer()));
        QObject::connect(&view, SIGNAL(disconnectFromServer()), connector, SLOT(disconnectFromServer()));
        QObject::connect(&view, SIGNAL(startRecording()), connector, SLOT(startRecording()));
        QObject::connect(&view, SIGNAL(commitRecording()), connector, SLOT(commitRecording()));
        QObject::connect(&view, SIGNAL(configurationChanged()), connector, SLOT(configurationChanged()));

        QObject::connect(connector, SIGNAL(connectionState(ConnectionState)), &view, SLOT(displayConnectionState(ConnectionState)));
        QObject::connect(connector, SIGNAL(status(QString)), &view, SLOT(displayStatus(QString)));
        QObject::connect(connector, SIGNAL(error(QString)), &view, SLOT(displayError(QString)));
        QObject::connect(connector, SIGNAL(listening()), &view, SLOT(displayListening()));
        QObject::connect(connector, SIGNAL(recognizing()), &view, SLOT(displayRecognizing()));
        QObject::connect(connector, SIGNAL(microphoneLevel(int,int,int)), &view, SLOT(displayMicrophoneLevel(int,int,int)));
        //QObject::connect(connector, SIGNAL(recognized(QString)), &view, SLOT(displayExecutedAction(QString)));
        QObject::connect(connector, SIGNAL(recognized(QString)), &recomment, SLOT(critique(QString)));
    }

    QObject::connect(&recomment, SIGNAL(recommend(const Offer*, QString)), &view, SLOT(displayRecommendation(const Offer*, QString)));
    QObject::connect(&recomment, SIGNAL(noMatchFor(QString)), &view, SLOT(displayNoMatch(QString)));

    view.show();
    if (voiceControlled)
        connector->init();
    if (!recomment.init()) {
        qWarning() << "Failed to initialize Recomment; Aborting";
        return -1;
    }

    int ret = app.exec();
    delete connector;
    return ret;
}
int CellularTechnologies::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 14)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 14;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = cellSearchStatus(); break;
        case 1: *reinterpret_cast< QStringList*>(_v) = configuredTechnologies(); break;
        case 2: *reinterpret_cast< QString*>(_v) = connectionState(); break;
        case 3: *reinterpret_cast< QString*>(_v) = displayedCarrierName(); break;
        case 4: *reinterpret_cast< QString*>(_v) = homeCountry(); break;
        case 5: *reinterpret_cast< bool*>(_v) = isOnEmergencyCall(); break;
        case 6: *reinterpret_cast< QString*>(_v) = networkTechnology(); break;
        case 7: *reinterpret_cast< QString*>(_v) = parentCarrierName(); break;
        case 8: *reinterpret_cast< bool*>(_v) = roaming(); break;
        case 9: *reinterpret_cast< QString*>(_v) = scanMode(); break;
        case 10: *reinterpret_cast< int*>(_v) = signalStrengthBars(); break;
        case 11: *reinterpret_cast< int*>(_v) = signalStrengthRssi(); break;
        case 12: *reinterpret_cast< QString*>(_v) = technologyIndicator(); break;
        }
        _id -= 13;
    } else if (_c == QMetaObject::WriteProperty) {
        _id -= 13;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 13;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 13;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 13;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 13;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 13;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 13;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
void ConnectionAgentPlugin::connectToConnectiond(QString)
{
    if (connManagerInterface) {
        delete connManagerInterface;
        connManagerInterface = 0;
    }

    if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(CONND_SERVICE)) {
        qDebug() << Q_FUNC_INFO << QString("connection service not available").arg(CONND_SERVICE);
        QDBusReply<void> reply = QDBusConnection::sessionBus().interface()->startService(CONND_SERVICE);

        if (!reply.isValid()) {
            qDebug() << Q_FUNC_INFO << reply.error().message();
            return;
        }
    }

    connManagerInterface = new com::jolla::Connectiond(CONND_SERVICE, CONND_PATH,
                                                       QDBusConnection::sessionBus(), this);
    if (!connManagerInterface->isValid()) {
        qDebug() << Q_FUNC_INFO << "is not valid interface";
    }
    connect(connManagerInterface,SIGNAL(connectionRequest()),
            this,SLOT(onConnectionRequested()));
    connect(connManagerInterface,SIGNAL(configurationNeeded(QString)),
            this,SIGNAL(configurationNeeded(QString)));

    connect(connManagerInterface,SIGNAL(userInputCanceled()),
            this,SIGNAL(userInputCanceled()));

    connect(connManagerInterface, SIGNAL(errorReported(QString, QString)),
            this, SLOT(onErrorReported(QString, QString)));

    connect(connManagerInterface,SIGNAL(connectionState(QString, QString)),
                     this,SLOT(onConnectionState(QString, QString)));

    connect(connManagerInterface,SIGNAL(requestBrowser(QString)),
                     this,SLOT(onRequestBrowser(QString)));

    connect(connManagerInterface,SIGNAL(userInputRequested(QString,QVariantMap)),
                     this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);

    connect(connManagerInterface,SIGNAL(tetheringFinished(bool)),
            this,SLOT(onTetheringFinished(bool)));
}
Пример #12
0
void SimondConnector::connectToServer()
{
    emit status(tr("Connecting to server, please wait..."));
    emit connectionState(Connecting);

    QString server      = Settings::publicServer() ? "grasch.net" : Settings::host();
    int port            = Settings::publicServer() ? 4444 : Settings::port();

    if (socket->state() != QAbstractSocket::UnconnectedState)
      socket->abort();

    if (false) { //SSL
      socket->setProtocol(QSsl::TlsV1);
      socket->connectToHostEncrypted( server, port );
    } else {
      socket->connectToHost(server, port);
    }

    timeoutTimer->start();
}
int WifiWatcher::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 8)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = lanTetherPowerEnabled(); break;
        case 1: *reinterpret_cast< QString*>(_v) = lanTetherState(); break;
        case 2: *reinterpret_cast< QVariantList*>(_v) = scanResults(); break;
        case 3: *reinterpret_cast< bool*>(_v) = connected(); break;
        case 4: *reinterpret_cast< QString*>(_v) = connectionState(); break;
        case 5: *reinterpret_cast< QString*>(_v) = connectionSsid(); break;
        case 6: *reinterpret_cast< QString*>(_v) = connectionBssid(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #14
0
void SimondConnector::messageReceived()
{
    waitFor(sizeof(qint32));
    qint32 code;

    *response >> code;
    qDebug() << "Message received: " << code;
    switch (code) {
    case Simond::VersionIncompatible:
        emit error(tr("Server version incompatible with client."));
        disconnectFromServer();
        break;
    case Simond::AuthenticationFailed:
        emit error(tr("Authentication failed. Please check the configured user name and password in the configuration."));
        disconnectFromServer();
        break;
    case Simond::LoginSuccessful:
        emit status(tr("Logged in"));
        break;
    case Simond::RecognitionReady:
        emit status(tr("Recognition ready; Activating..."));
        sendRequest(Simond::StartRecognition);
        break;
    case Simond::RecognitionStarted:
        emit status("Recognition activated");
        emit connectionState(Connected);
        break;
    case Simond::RecognitionError: {
        parseLength();
        QByteArray errorMessage, protocol;
        *response >> errorMessage;
        *response >> protocol;
        emit error(tr("Recognition reported error: ").arg(QString::fromUtf8(errorMessage)));
        disconnectFromServer();
        break;
    }
    case Simond::RecognitionWarning: {
        parseLength();
        QByteArray warningMessage;
        *response >> warningMessage;
        emit error(tr("Recognition reported warning: %1").arg(QString::fromUtf8(warningMessage)));
        break;
    }
    case Simond::RecognitionStopped:
        break; //nothing to do
    case Simond::RecognitionResult: {
        parseLength();

        qint8 sentenceCount;
        *response >> sentenceCount;
        RecognitionResultList recognitionResults;

        for (int i=0; i < sentenceCount; i++) {
          QByteArray word, sampa, samparaw;
          QList<float> confidenceScores;
          *response >> word;
          *response >> sampa;
          *response >> samparaw;
          *response >> confidenceScores;
          recognitionResults.append(RecognitionResult(QString::fromUtf8(word),
            QString::fromUtf8(sampa),
            QString::fromUtf8(samparaw),
            confidenceScores));
        }
        emit recognized(recognitionResults);
        break;
    }

    default:
        qDebug() << "Unhandled request: " << code;
    }
    if (socket->bytesAvailable())
        messageReceived();
}
void ConnectionAgentPlugin::onConnectionState(const QString &state, const QString &type)
{
    qDebug() << Q_FUNC_INFO << state;
    Q_EMIT connectionState(state, type);
}
Пример #16
0
void QConnectionManager::serviceStateChanged(const QString &state)
{
    NetworkService *service = static_cast<NetworkService *>(sender());
    qDebug() << state << service->name();

    if (currentNetworkState == "disconnect") {
        ua->sendConnectReply("Clear");
    }
    if (state == "failure") {
        serviceInProgress.clear();

        Q_EMIT errorReported(service->path(), "Connection failure: "+ service->name());
        autoConnect();
    }
    if (currentNetworkState == "configuration" && state == "ready"
            && netman->state() != "online") {
        goodConnectTimer->start();
    }

    //manual connection
    if ((state == "ready" || state == "online") && service->path() != serviceInProgress) {
        qDebug() << "manual connection of" << service->path() << "detected, enabling auto connect timeout";
        lastManuallyConnectedService = service->path();
        manualConnnectionTimer.start();
    }

    //auto migrate
    if (service->path() == serviceInProgress
            && state == "online") {
        serviceInProgress.clear();
    }

    //auto migrate
    if (state == "idle") {
        if (lastManuallyConnectedService == service->path()) {
            lastManuallyConnectedService.clear();
            manualConnnectionTimer.invalidate();
        }

        if (serviceInProgress == service->path())
            serviceInProgress.clear();

        previousConnectedService = service->path();
        if (service->type() == "ethernet") { //keep this alive
            NetworkTechnology tech;
            tech.setPath(netman->technologyPathForService(service->path()));
            if (tech.powered()) {
               requestConnect(service->path());
            }
        } else {
            updateServicesMap();
            qDebug() <<"serviceInProgress"<< serviceInProgress;
            // If a manual connection has recently been detected autoConnect() will do nothing.
            // Always call autoConnect() here as this state change could be that manual connection
            // disconnecting.
            autoConnect();
        }
    }

    if (!(currentNetworkState == "online" && state == "association"))
        Q_EMIT connectionState(state, service->type());

        currentNetworkState = state;
        QSettings confFile;
        confFile.beginGroup("Connectionagent");
        confFile.setValue("connected",currentNetworkState);
}