示例#1
0
void Settings::SaveSettings()
{
    pSettings->setValue("windowState", pMain->saveState());

    if(!pMain->isMaximized())
        pSettings->setValue("windowSize", pMain->saveGeometry());

    pSettings->setValue("windowMaximized", pMain->isMaximized());

    pSettings->setValue("splitterState", pMain->GetUi()->splitter->saveState());

    pSettings->setValue("rulesSplitterState", pMain->GetUi()->rulesSplitter->saveState());

    pSettings->setValue("browserSplitterState", pMain->GetUi()->browserSplitter->saveState());

    pSettings->setValue("browserTableState", pMain->GetUi()->browserTable->horizontalHeader()->saveState());

    pSettings->setValue("rulesTableState", pMain->GetUi()->rulesTable->horizontalHeader()->saveState());

    pSettings->setValue("playerTableState", pMain->GetUi()->playerTable->horizontalHeader()->saveState());

    pSettings->setValue("darkTheme", pMain->GetUi()->menuSettings->actions().at(0)->isChecked());

    pSettings->setValue("showLoggingInfo", pMain->showLoggingInfo);

    pSettings->setValue("logPort", pMain->u16logPort);

    pSettings->beginGroup("servers");

    pSettings->remove("");

    if(serverList.size() > 0)
    {
        for(int i = 0; i < serverList.size(); i++)
        {
            ServerInfo *info = serverList.at(i);
            QStringList list;
            list.append(info->ipPort);

            if(info->saveRcon && info->rconPassword.length() >0)
            {
                SimpleCrypt encrypt;
                encrypt.setKey(info->ipPort.toLongLong());
                list.append(encrypt.encryptToString(info->rconPassword));

            }
            pSettings->setValue(QString::number(i+1), list);
        }
    }

    pSettings->endGroup();
}
示例#2
0
void Settings::ReadSettings()
{
    if(!pSettings->value("windowMaximized", pMain->isMaximized()).toBool())
    {
        pMain->restoreGeometry(pSettings->value("windowSize", pMain->saveGeometry()).toByteArray());
    }

    pMain->restoreState(pSettings->value("windowState", pMain->saveState()).toByteArray());

    pMain->GetUi()->splitter->restoreState(pSettings->value("splitterState", pMain->GetUi()->splitter->saveState()).toByteArray());

    pMain->GetUi()->rulesSplitter->restoreState(pSettings->value("rulesSplitterState", pMain->GetUi()->rulesSplitter->saveState()).toByteArray());

    pMain->GetUi()->browserSplitter->restoreState(pSettings->value("browserSplitterState", pMain->GetUi()->browserSplitter->saveState()).toByteArray());

    pMain->GetUi()->browserTable->horizontalHeader()->restoreState(pSettings->value("browserTableState", pMain->GetUi()->browserTable->horizontalHeader()->saveState()).toByteArray());

    pMain->GetUi()->playerTable->horizontalHeader()->restoreState(pSettings->value("playerTableState", pMain->GetUi()->playerTable->horizontalHeader()->saveState()).toByteArray());

    pMain->GetUi()->rulesTable->horizontalHeader()->restoreState(pSettings->value("rulesTableState", pMain->GetUi()->rulesTable->horizontalHeader()->saveState()).toByteArray());

    bool darkTheme = pSettings->value("darkTheme", false).toBool();

    pMain->showLoggingInfo = pSettings->value("showLoggingInfo", true).toBool();

    uint temp = pSettings->value("logPort", pMain->u16logPort).toUInt();

    if(temp <= PORT_MAX && temp >= PORT_MIN)
    {
        pMain->u16logPort = temp;
    }

    if(darkTheme)
    {
        pMain->GetUi()->menuSettings->actions().at(0)->setChecked(true);
        pMain->darkThemeTriggered();
    }

    pSettings->beginGroup("servers");
    QStringList keys = pSettings->childKeys();

    for(int i = 1; i <= keys.size(); i++)
    {   
        QStringList list = pSettings->value(QString::number(i), QStringList()).toStringList();

        if(list.size() == 0 || list.size() > 2)
        {
            continue;
        }

        if(pMain->CheckServerList(list.at(0)) == AddServerError_None)
        {
            ServerInfo *info = new ServerInfo(list.at(0));
            serverList.append(info);

            int row = pMain->GetUi()->browserTable->rowCount();
            pMain->GetUi()->browserTable->insertRow(row);

            QTableWidgetItem *item = new QTableWidgetItem();
            QTableWidgetItem *id = new QTableWidgetItem();
            id->setData(Qt::DisplayRole, serverList.size());

            item->setTextColor(queryingColor);
            item->setText(QString("Querying server %1...").arg(info->ipPort));
            item->setToolTip(info->ipPort);
            pMain->GetUi()->browserTable->setItem(row, 0, id);
            pMain->GetUi()->browserTable->setItem(row, 4, item);

            InfoQuery *infoQuery = new InfoQuery(pMain);
            infoQuery->query(&info->host, info->port, id);

            if(list.size() == 2)
            {
                SimpleCrypt encrypt;
                encrypt.setKey(list.at(0).toLongLong());
                QString pass = encrypt.decryptToString(list.at(1));
                if(encrypt.lastError() == SimpleCrypt::ErrorNoError)
                {
                    info->rconPassword = pass;
                    info->saveRcon = true;
                }
            }
        }
    }
    pSettings->endGroup();
    this->SaveSettings();//Call this again to make sure we cleaned up any garbage entries
}