Esempio n. 1
0
inline ConstStringT cs_format_va(size_t hint, CharT const* fmt, va_list args)
{
    typedef ConstStringT string;
    typedef typename string::char_type char_type;
    typedef typename string::storage_type storage_type;

    if (!hint)
        hint = string::traits_type::length(fmt);
    ++hint; // include the trailing zero

    // first take - try not to allocate any memory
    enum { buffers_chars = storage_type::effective_buffer_size_chars };
    if (buffers_chars && hint <= buffers_chars)
    {
        storage_type stg(0, buffers_chars - 1);
        int const r(cs::aux::do_format(const_cast<char_type*>(stg.begin()), buffers_chars, fmt, args));
        if (size_t(r) < buffers_chars)
            return string(stg.set_size(r));
        else
            hint = 2 * buffers_chars;
    }

    // grow buffer till it fits
    for (; true; hint *= 2)
    {
        storage_type stg(0, hint - 1);
        int const r(cs::aux::do_format(const_cast<char_type*>(stg.begin()), hint, fmt, args));
        if (size_t(r) < hint)
            return string(stg.set_size(r));
    }
    // never get here
}
Esempio n. 2
0
League::League(QString dir, QString title, QString country, QStringList teams, QStringList gmrs, bool views)
        :Tournament (dir, title, country, teams, gmrs, views)
{
    QSettings stg(workdir + "/settings.ini", QSettings::IniFormat, this);
    stg.beginGroup("Tournament");
    stg.setValue("type", "league");
stg.endGroup();
stg.sync();
}
Esempio n. 3
0
int KouetsApp::SaveIni()
{
    if (!updated_)
        return 0;

    int ret = 0;

    QSettings stg(GetIniPath(), QSettings::IniFormat);

    stg.setValue("program", programPath_);
    stg.setValue("commandline", cmdLine_);
    stg.setValue("decoration", decoration_);
    stg.setValue("activatetab", bactivateprocessedtab_);
    stg.setValue("linewrap", blinewrap_);

    updated_ = false;

    return ret;
}
Esempio n. 4
0
/**
 * load ini file.
 *
 * @return zero if loaded.
 */
int KouetsApp::LoadIni()
{
    int ret = 0;

    QSettings stg(GetIniPath(), QSettings::IniFormat);

    QVariant var = stg.value("program");
    programPath_ = var.toString();
    var = stg.value("commandline");
    cmdLine_ = var.toString();
    var = stg.value("decoration");
    decoration_ = var.toString();
    var = stg.value("activatetab", 1);
    bactivateprocessedtab_ = var.toInt();
    var = stg.value("linewrap", 1);
    blinewrap_ = var.toInt();

    updated_ = false;

    return ret;
}
Esempio n. 5
0
void MainWindow::on_actOpen_triggered()
{
    if (loaded) {

    }


    QString dir = QFileDialog::getExistingDirectory(this, "Выберите папку турнира", QDir::homePath(), QFileDialog::ShowDirsOnly);
    QDir d (dir);
    if (dir.isEmpty()) {return;}
    if (!d.exists(dir + "/tour.db"))
    {
        QMessageBox::critical(this, "Ошибка", "Не найдена БД турнира");
          return;
            }
    QSettings stg(dir+"/settings.ini", QSettings::IniFormat, this);
    stg.beginGroup("Tournament");
    QString type = stg.value("type", "F**K").toString();
    if (type =="league") {
trn = new League (dir);
}
    else if (type == "cup") {
       trn= new Cup(dir);
          }
QStringList lst = trn->getData(1).toStringList();
 appendTable();
   createMenus();
      setWindowTitle(tr("%1 - RKS Manager").arg(trn->title()));
      QString *message = new QString();
 if (trn->checkPlanning(message))
     ui->actPlanning->setText(tr("Спланировать: %1").arg(QVariant(*message).toString()));
else
    ui->mnuLeague->removeAction(ui->actPlanning);
ui->tableWidget->sortByColumn(8);

   loaded = true;
   createStatusBar();
}
Esempio n. 6
0
//-------------------------------------------------------------------------------------------------
void ExchangeRate::slotReplyFin(QNetworkReply *netrep)
{
    if (netrep->error())
    {
        QMessageBox::warning(this, 0, tr("Connection error:") + ' ' + netrep->errorString());
        return;
    }

    const QByteArray baRead = netrep->readAll();
    int iSep = baRead.indexOf("<a href=\"/control/en/curmetal/detail/currency?period=daily\">", 40000);
    if (iSep > 0)
    {
        iSep = baRead.lastIndexOf("</td>", iSep);
        if (iSep > 0)
        {
            const QString strDate = baRead.mid(iSep-10, 10);        //[10 = "dd.MM.yyyy"]
            if (QDateTime::fromString(strDate, "dd.MM.yyyy").isValid())
            {
                iSep = baRead.indexOf("<td class=\"attribute\">100&nbsp;US Dollar</td>", iSep+70);
                if (iSep > 0)
                {
                    iSep = baRead.indexOf("<td class=\"value\" nowrap=\"nowrap\">", iSep+45);
                    if (iSep > 0)
                    {
                        iSep += 34;
                        int iEnd = baRead.indexOf('\n', iSep);
                        if (iEnd > 0)
                        {
                            const double dPerUsd = baRead.mid(iSep, iEnd-iSep-1).toDouble();
                            if (dPerUsd > 300.0 && dPerUsd < 8000.0)
                            {
                                iSep = baRead.indexOf("<td class=\"attribute\">100&nbsp;EURO</td>", iSep+100);
                                if (iSep > 0)
                                {
                                    iSep = baRead.indexOf("<td class=\"value\" nowrap=\"nowrap\">", iSep+40);
                                    if (iSep > 0)
                                    {
                                        iSep += 34;
                                        iEnd = baRead.indexOf('\n', iSep);
                                        if (iEnd > 0)
                                        {
                                            const double dPerEur = baRead.mid(iSep, iEnd-iSep-1).toDouble();
                                            if (dPerEur > 300.0 && dPerEur < 8000.0)
                                            {
                                                iSep = baRead.indexOf("<td class=\"attribute\">10&nbsp;Russian ruble</td>", iSep+100);
                                                if (iSep > 0)
                                                {
                                                    iSep = baRead.indexOf("<td class=\"value\" nowrap=\"nowrap\">", iSep+48);
                                                    if (iSep > 0)
                                                    {
                                                        iSep += 34;
                                                        iEnd = baRead.indexOf('\n', iSep);
                                                        if (iEnd > 0)
                                                        {
                                                            const double dPerRub = baRead.mid(iSep, iEnd-iSep-1).toDouble();
                                                            if (dPerRub > 1.0 && dPerRub < 10.0)
                                                            {
                                                                iSep = 0;
                                                                dUahPerUsd = dPerUsd/100.0;
                                                                dUahPerEur = dPerEur/100.0;
                                                                dUahPerRub = dPerRub/10.0;

                                                                const QString strUahPerUsd = QString::number(dUahPerUsd, 'f', 6),
                                                                        strUahPerEur = QString::number(dUahPerEur, 'f', 6),
                                                                        strUahPerRub = QString::number(dUahPerRub, 'f', 5);

                                                                lblNote->setText(strDate + "\n1 USD = " + strUahPerUsd + " UAH\n1 EUR = " + strUahPerEur + " UAH\n1 UAH = " + QString::number(1.0/dUahPerRub, 'f', 6) + " RUB");

                                                                QSettings stg(strAppStg, QSettings::IniFormat);
                                                                stg.beginGroup("Settings");
                                                                stg.setValue("DateTime", strDate);
                                                                stg.setValue("USD", strUahPerUsd);
                                                                stg.setValue("EUR", strUahPerEur);
                                                                stg.setValue("RUB", strUahPerRub);
                                                                stg.endGroup();

                                                                lblInfo->setText(tr("Successfully"));
                                                                gbMain->setEnabled(true);
                                                                QTimer::singleShot(1300, lblInfo, SLOT(clear()));
                                                            }
                                                            else
                                                                iSep = 114;
                                                        }
                                                        else
                                                            iSep = 113;
                                                    }
                                                    else
                                                        iSep = 112;
                                                }
                                                else
                                                    iSep = 111;
                                            }
                                            else
                                                iSep = 110;
                                        }
                                        else
                                            iSep = 109;
                                    }
                                    else
                                        iSep = 108;
                                }
                                else
                                    iSep = 107;
                            }
                            else
                                iSep = 106;
                        }
                        else
                            iSep = 105;
                    }
                    else
                        iSep = 104;
                }
                else
                    iSep = 103;
            }
            else
                iSep = 102;
        }
        else
            iSep = 101;
    }
    else
        iSep = 100;

    if (iSep)
        QMessageBox::warning(this, 0, tr("Error:") + " #" + QString::number(iSep));
}
Esempio n. 7
0
//-------------------------------------------------------------------------------------------------
void ExchangeRate::slotShowSettings()
{
    QDialog dialSettings(this, Qt::WindowCloseButtonHint);
    QLabel *lblPrecision = new QLabel(tr("Precision:"), &dialSettings);
    QSpinBox *sbPrecision = new QSpinBox(&dialSettings);
    sbPrecision->setRange(0, 10);
    sbPrecision->setValue(iPrecision);
    QHBoxLayout *hblPrecision = new QHBoxLayout;
    hblPrecision->addWidget(lblPrecision, 0, Qt::AlignRight);
    hblPrecision->addWidget(sbPrecision, 0, Qt::AlignLeft);

    QCheckBox *chbProxy = new QCheckBox(tr("Use proxy"), &dialSettings);
    chbProxy->setChecked(bUseProxy);
    lblType = new QLabel(tr("Type:"), &dialSettings);
    cbType = new QComboBox(&dialSettings);
    cbType->addItems(QStringList("HTTP") << "SOCKS5");
    cbType->setCurrentIndex(bProxyIsSocks);
    lblServer = new QLabel(tr("Server:"), &dialSettings);
    leServer = new QLineEdit(&dialSettings);
    leServer->setText(strServer);
    lblPort = new QLabel(tr("Port:"), &dialSettings);
    sbPort = new QSpinBox(&dialSettings);
    sbPort->setRange(1, 65535);
    sbPort->setValue(iPort);
    chbAuth = new QCheckBox(tr("Authorization"), &dialSettings);
    chbAuth->setChecked(bAuth);
    lblUser = new QLabel(tr("User:"******"Password:"******"Proxy"), &dialSettings);
    QGridLayout *glProxy = new QGridLayout(gbProxy);
    glProxy->addWidget(chbProxy, 0, 1);
    glProxy->addWidget(lblType, 1, 0);
    glProxy->addWidget(cbType, 1, 1);
    glProxy->addWidget(lblServer, 2, 0);
    glProxy->addWidget(leServer, 2, 1);
    glProxy->addWidget(lblPort, 3, 0);
    glProxy->addWidget(sbPort, 3, 1);
    glProxy->addWidget(chbAuth, 4, 1);
    glProxy->addWidget(lblUser, 5, 0);
    glProxy->addWidget(leUser, 5, 1);
    glProxy->addWidget(lblPassword, 6, 0);
    glProxy->addWidget(lePassword, 6, 1);

    QPushButton *pbOk = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton), "OK", this);

    QVBoxLayout *vblStg = new QVBoxLayout(&dialSettings);
    vblStg->addLayout(hblPrecision);
    vblStg->addWidget(gbProxy);
    vblStg->addWidget(pbOk, 0, Qt::AlignHCenter);

    dialSettings.setFixedHeight(dialSettings.minimumSizeHint().height());

    //connects
    connect(chbProxy, SIGNAL(toggled(bool)), this, SLOT(slotToggleProxy(bool)));
    connect(chbAuth, SIGNAL(toggled(bool)), this, SLOT(slotToggleAuth(bool)));
    connect(pbOk, SIGNAL(clicked()), &dialSettings, SLOT(accept()));

    if (dialSettings.exec() == QDialog::Accepted)
    {
        iPrecision = sbPrecision->value();
        bUseProxy = chbProxy->isChecked();
        bProxyIsSocks = cbType->currentIndex();
        strServer = leServer->text();
        iPort = sbPort->value();
        bAuth = chbAuth->isChecked();
        strUser = leUser->text();
        strPassword = lePassword->text();

        if (bUseProxy)
        {
            QNetworkProxy netProxy(bProxyIsSocks ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy, strServer, iPort);
            if (bAuth)
            {
                netProxy.setUser(strUser);
                netProxy.setPassword(strPassword);
            }
            nam->setProxy(netProxy);
        }
        else
            nam->setProxy(QNetworkProxy());

        QSettings stg(strAppStg, QSettings::IniFormat);
        stg.setIniCodec("UTF-8");
        stg.beginGroup("Settings");
        stg.setValue("Precision", iPrecision);
        stg.setValue("UseProxy", bUseProxy ? "1" : "0");
        stg.setValue("ProxyType", bProxyIsSocks ? "SOCKS5" : "HTTP");
        stg.setValue("Server", strServer);
        stg.setValue("Port", QString::number(iPort));
        stg.setValue("Auth", bAuth ? "1" : "0");
        stg.setValue("User", strUser);
        stg.setValue("Password", strPassword);
        stg.endGroup();
    }
}
Esempio n. 8
0
//-------------------------------------------------------------------------------------------------
ExchangeRate::ExchangeRate() : QWidget(),
    nam(new QNetworkAccessManager(this)),
    iPrecision(2),
    bUseProxy(false),
    bProxyIsSocks(false),
    iPort(3128),
    bAuth(false),
    dMaxSum(100000000000000000000.05)
{
    const QString strAppName = qAppName(),
            strAppDir = qApp->applicationDirPath();
    strAppStg = strAppDir + '/' + strAppName + ".ini";
    QTranslator *translator = new QTranslator(this);
    if (translator->load(strAppName, strAppDir) || translator->load(strAppName + '_' + QLocale::system().name(), strAppDir))
        qApp->installTranslator(translator);

    leUah = new QLineEdit(this);
    QVBoxLayout *vblSpacing = new QVBoxLayout;
    vblSpacing->addSpacing(15);
    leUsd = new QLineEdit(this);
    leEur = new QLineEdit(this);
    leRub = new QLineEdit(this);
    gbMain = new QGroupBox(this);
    gbMain->setEnabled(false);
    QFormLayout *frml = new QFormLayout(gbMain);
    frml->addRow("UAH:", leUah);
    frml->addRow(vblSpacing);
    frml->addRow("USD:", leUsd);
    frml->addRow("EUR:", leEur);
    frml->addRow("RUB:", leRub);

    QPushButton *pbUpdate = new QPushButton(style()->standardIcon(QStyle::SP_BrowserReload), tr("Update"), this);
    lblInfo = new QLabel(this);
    QFont fontSaved = lblInfo->font();
    fontSaved.setItalic(true);
    lblInfo->setFont(fontSaved);
    QHBoxLayout *hblUpdate = new QHBoxLayout;
    hblUpdate->setContentsMargins(0, 0, 0, 0);
    hblUpdate->addWidget(pbUpdate);
    hblUpdate->addWidget(lblInfo);
    lblNote = new QLabel("?\n1 USD = ?\n1 EUR = ?\n1 UAH = ?", this);
    QGroupBox *gbNote = new QGroupBox(this);
    gbNote->setMinimumWidth(170);
    QVBoxLayout *vbNote = new QVBoxLayout(gbNote);
    vbNote->addLayout(hblUpdate);
    vbNote->addWidget(lblNote);

    QLabel *lblVer = new QLabel(cFullVersion, this);
    QPushButton *pbSettings = new QPushButton(style()->standardIcon(QStyle::SP_FileDialogDetailedView), 0, this);
    QHBoxLayout *hblBottom = new QHBoxLayout;
    hblBottom->addStretch();
    hblBottom->addWidget(lblVer);
    hblBottom->addWidget(pbSettings);
    QVBoxLayout *vblRight = new QVBoxLayout;
    vblRight->addWidget(gbNote);
    vblRight->addLayout(hblBottom, Qt::AlignRight);

    QHBoxLayout *hblMain = new QHBoxLayout(this);
    hblMain->addWidget(gbMain);
    hblMain->addLayout(vblRight);

    this->setMaximumHeight(this->minimumSizeHint().height());

    //connects
    connect(leUah, SIGNAL(textEdited(QString)), this, SLOT(slotFromUah(QString)));
    connect(leUsd, SIGNAL(textEdited(QString)), this, SLOT(slotFromUsd(QString)));
    connect(leEur, SIGNAL(textEdited(QString)), this, SLOT(slotFromEur(QString)));
    connect(leRub, SIGNAL(textEdited(QString)), this, SLOT(slotFromRub(QString)));
    connect(pbUpdate, SIGNAL(clicked()), this, SLOT(slotUpdate()));
    connect(pbSettings, SIGNAL(clicked()), this, SLOT(slotShowSettings()));
    connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotReplyFin(QNetworkReply*)));

    //settings
    QSettings stg(strAppStg, QSettings::IniFormat);
    stg.setIniCodec("UTF-8");
    if (stg.childGroups().contains("Settings"))
    {
        stg.beginGroup("Settings");
        const QString strDate = stg.value("DateTime").toString();
        if (QDateTime::fromString(strDate, "dd.MM.yyyy").isValid() &&
                (dUahPerUsd = stg.value("USD").toDouble()) > 3.0 && dUahPerUsd < 80.0 &&
                (dUahPerEur = stg.value("EUR").toDouble()) > 3.0 && dUahPerEur < 80.0 &&
                (dUahPerRub = stg.value("RUB").toDouble()) > 0.1 && dUahPerRub < 1.0)
        {
            lblNote->setText(strDate +
                             "\n1 USD = " + QString::number(dUahPerUsd, 'f', 6) +
                             " UAH\n1 EUR = " + QString::number(dUahPerEur, 'f', 6) +
                             " UAH\n1 UAH = " + QString::number(1.0/dUahPerRub, 'f', 6) +
                             " RUB");
            gbMain->setEnabled(true);
        }
        int iTemp = stg.value("Precision", -1).toInt();
        if (iTemp >= 0 && iTemp <= 10)
            iPrecision = iTemp;
        if (stg.value("UseProxy").toString() == "1")
            bUseProxy = true;
        if (stg.value("ProxyType") == "SOCKS5")
            bProxyIsSocks = true;
        strServer = stg.value("Server").toString();
        iTemp = stg.value("Port").toInt();
        if (iTemp > 0 && iTemp <= 65535)
            iPort = iTemp;
        if (stg.value("Auth").toString() == "1")
            bAuth = true;
        strUser = stg.value("User").toString();
        strPassword = stg.value("Password").toString();
        stg.endGroup();

        if (bUseProxy)
        {
            QNetworkProxy netProxy(bProxyIsSocks ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy, strServer, iPort);
            if (bAuth)
            {
                netProxy.setUser(strUser);
                netProxy.setPassword(strPassword);
            }
            nam->setProxy(netProxy);
        }
    }

    this->restoreGeometry(QSettings("UserPrograms", strAppName).value("Geometry").toByteArray());
}
Esempio n. 9
0
bool MyGLCanvas::oglInit()
{
    if ( !m_oglContext )
        return false;
    
    // The current context must be set before we get OGL pointers
    SetCurrent(*m_oglContext);
    
    // Initialize our OGL pointers
    if ( !myOGLManager::Init() )
    {
        wxMessageBox("Error: Some OpenGL pointer to function failed.",
                     "OpenGL initialization error", wxOK | wxICON_INFORMATION, this);
        return false;
    }
    
    // Create our OGL manager, pass our OGL error handler
    m_oglManager = new myOGLManager(&fOGLErrHandler);
    
    // Get the GL version for the current OGL context
    wxString sglVer = "\nUsing OpenGL version: ";
    sglVer += wxString::FromUTF8(
                                 reinterpret_cast<const char *>(m_oglManager->GetGLVersion()) );
    // Also Vendor and Renderer
    sglVer += "\nVendor: ";
    sglVer += wxString::FromUTF8(
                                 reinterpret_cast<const char *>(m_oglManager->GetGLVendor()) );
    sglVer += "\nRenderer: ";
    sglVer += wxString::FromUTF8(
                                 reinterpret_cast<const char *>(m_oglManager->GetGLRenderer()) );
    // For the menu "About" info
    m_parent->SetOGLString(sglVer);
    
    // Load some data into GPU
    m_oglManager->SetShadersAndTriangles();
    
    // This string will be placed on a face of the pyramid
    int swi = 0, shi = 0; //Image sizes
    wxString stg("wxWidgets");
    // Set the font. Use a big pointsize so as to smoothing edges.
    wxFont font(48, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
    if ( !font.IsOk() )
        font = *wxSWISS_FONT;
    wxColour bgrdColo(*wxBLACK);
    wxColour foreColo(160, 0, 200); // Dark purple
    // Build an array with the pixels. Background fully transparent
    unsigned char* sPixels = MyTextToPixels(stg, font, foreColo, bgrdColo, 0,
                                            &swi, &shi);
    // Send it to GPU
    m_oglManager->SetStringOnPyr(sPixels, swi, shi);
    delete[] sPixels; // That memory was allocated at MyTextToPixels
    
    // This string is placed at left bottom of the window. Its size doesn't
    // change with window size.
    stg = "Rotate the pyramid with\nthe left mouse button";
    font.SetPointSize(14);
    bgrdColo = wxColour(40, 40, 255);
    foreColo = wxColour(*wxWHITE);
    unsigned char* stPixels = MyTextToPixels(stg, font, foreColo, bgrdColo, 80,
                                             &swi, &shi);
    m_oglManager->SetImmutableString(stPixels, swi, shi);
    delete[] stPixels;
    
    return true;
}