AccountSummaryWidget::AccountSummaryWidget( CurrencyTicker* ticker, QWidget* parent )
: QFrame( parent )
, optionsModel ( NULL )
, m_ticker( ticker )
, ui( new Ui::AccountSummaryWidget )
, m_account ( NULL )
{
    ui->setupUi( this );

    ui->accountSettings->setTextFormat( Qt::RichText );
    ui->accountSettings->setText(GUIUtil::fontAwesomeRegular("\uf013"));

    //Zero out all margins so that we can handle whitespace in stylesheet instead.
    ui->accountBalance->setContentsMargins( 0, 0, 0, 0 );
    ui->accountBalanceForex->setContentsMargins( 0, 0, 0, 0 );
    ui->accountName->setContentsMargins( 0, 0, 0, 0 );
    ui->accountSettings->setContentsMargins( 0, 0, 0, 0 );


    //Hand cursor for clickable elements.
    ui->accountSettings->setCursor( Qt::PointingHandCursor );
    ui->accountBalanceForex->setCursor( Qt::PointingHandCursor );

    //We hide the forex value until we get a response from ticker
    ui->accountBalanceForex->setVisible( false );


    //Signals.
    connect( m_ticker, SIGNAL( exchangeRatesUpdated() ), this, SLOT( updateExchangeRates() ) );
    connect( ui->accountSettings, SIGNAL( clicked() ), this, SIGNAL( requestAccountSettings() ) );
    connect( ui->accountBalanceForex, SIGNAL( clicked() ), this, SIGNAL( requestExchangeRateDialog() ) );
}
void AccountSummaryWidget::disconnectSlots()
{
    disconnect( ui->accountBalanceForex, SIGNAL( clicked() ), this, SIGNAL( requestExchangeRateDialog() ) );
    disconnect( ui->accountSettings, SIGNAL( clicked() ), this, SIGNAL( requestAccountSettings() ) );
    disconnect( m_ticker, SIGNAL( exchangeRatesUpdated() ), this, SLOT( updateExchangeRates() ) );
    if (optionsModel && optionsModel->guldenSettings)
        disconnect( optionsModel->guldenSettings, SIGNAL(  localCurrencyChanged(QString) ), this, SLOT( updateExchangeRates() ) );
}
Exemplo n.º 3
0
void CurrencyTicker::netRequestFinished(QNetworkReply* reply)
{
    bool signalUpdates = false;

    if (reply->error() != QNetworkReply::NetworkError::NoError) {

    } else {
        int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

        if (statusCode != 200) {

        } else {
            QByteArray jsonReply = reply->readAll();
            QString temp = QString::fromStdString(jsonReply.data());
            QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonReply);
            QJsonArray jsonArray = jsonDoc.object().value("data").toArray();

            for (auto jsonVal : jsonArray) {
                QJsonObject jsonObject = jsonVal.toObject();
                std::string currencyName = jsonObject.value("name").toString().toStdString();
                std::string currencyCode = jsonObject.value("code").toString().toStdString();

                std::string currencyRate;
                std::ostringstream bufstream;
                bufstream << std::fixed << std::setprecision(8) << jsonObject.value("rate").toDouble();
                currencyRate = bufstream.str();

                m_ExchangeRates[currencyCode] = currencyRate;
                signalUpdates = true;
            }
        }
    }

    if (signalUpdates) {
        Q_EMIT exchangeRatesUpdated();
        if (++count % 20 == 0) {
            Q_EMIT exchangeRatesUpdatedLongPoll();
        }
    }

    QTimer::singleShot(10000, this, SLOT(pollTicker()));
}