Beispiel #1
0
void Asterisk::onSocketReadyRead()
{
//    qDebug("<ready-read>");

    QVariantHash headers;

    while (socket.canReadLine()) {
        QByteArray line = socket.readLine();

//        qDebug() << "Line:" << line;

        if (line != "\r\n") {
            QStringList header = QString(line.trimmed()).split(':');

            headers.insertMulti(header[0], decodeValue(header[1].trimmed()));
        } else {
            if (headers.contains("Response"))
                responses.insert(headers.take("ActionID").toString(), headers);
            else if (headers.contains("Event"))
                emit eventReceived(headers.take("Event").toString(), headers);

            headers.clear();
        }
    }

//    qDebug("</ready-read>");
}
void
HatchetAccountConfig::login()
{
    tLog() << Q_FUNC_INFO;
    const ButtonAction action = static_cast< ButtonAction>( m_ui->loginButton->property( "action" ).toInt() );

    if ( action == Login )
    {
        // Log in mode
        tLog() << Q_FUNC_INFO << "Logging in...";
        m_account->loginWithPassword( m_ui->usernameEdit->text(), m_ui->passwordEdit->text(), m_ui->otpEdit->text() );
    }
    else if ( action == Logout )
    {
        // TODO
        m_ui->usernameEdit->clear();
        m_ui->passwordEdit->clear();
        m_ui->otpEdit->clear();

        QVariantHash creds = m_account->credentials();
        creds.clear();
        m_account->setCredentials( creds );
        m_account->sync();
        m_account->deauthenticate();
    }
}
QJsonArray jsonHandler::modelToJson(QStandardItemModel *model, QStringList *list)
{
    QJsonArray jArray;
    QVariant modelValue;
    QVariantHash valueMap;

    for(int row = 0; row < model->rowCount(); ++row)
    {
        for(int col = 0; col < list->count(); ++col)
        {
            valueMap.insert(list->at(col),model->data(model->index(row,col)));
        }
        jArray.insert(row,QJsonObject::fromVariantHash(valueMap));
        valueMap.clear();
    }
    return jArray;
}