/* GNU General Public License version 3 notice Copyright (C) 2012 Mihawk . All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see < http://www.gnu.org/licenses/ >. */ #include "Settings.h" #include #include #include #include Settings* Settings::ourInstance = NULL; QSettings* Settings::ourSettings; Settings::Settings() { ourSettings = new QSettings(QCoreApplication::applicationDirPath() + "/cimsqwbot.cfg", QSettings::IniFormat); } Settings::~Settings() { delete ourSettings; } bool Settings::changeConfigFile(const QString &fileName) { delete ourSettings; ourSettings = new QSettings(fileName, QSettings::IniFormat); QSettings::Status status = ourSettings->status(); if(status != QSettings::NoError) { printf("Failed to load config file [%s]. Falling back to default config file.\n", fileName.toAscii().data()); delete ourSettings; ourSettings = NULL; return false; } return true; } Settings* Settings::globalInstance() { if(!ourInstance) ourInstance = new Settings(); return ourInstance; } QStringList Settings::serverList() { QStringList list; int size = ourSettings->beginReadArray("servers"); for(int i = 0; i < size; ++i) { ourSettings->setArrayIndex(i); list.append(ourSettings->value("address").toString()); } ourSettings->endArray(); return list; } void Settings::setServerList(QStringList &list) { ourSettings->beginWriteArray("servers"); for(int i = 0; i < list.size(); ++i) { ourSettings->setArrayIndex(i); ourSettings->setValue("address", list.at(i)); } ourSettings->endArray(); } QString Settings::quakeFolder() const { return ourSettings->value("quakeFolder", QCoreApplication::applicationDirPath()).toString(); } QString Settings::botName() const { return ourSettings->value("botName", "[ServeMe]").toString(); } int Settings::botPing() const { return ourSettings->value("botPing", 666).toInt(); } int Settings::botTopColor() const { return ourSettings->value("botTopColor", 11).toInt(); } int Settings::botBottomColor() const { return ourSettings->value("botBottomColor", 12).toInt(); } bool Settings::botSpectator() const { return ourSettings->value("botSpectator", true).toBool(); } int Settings::floodProtTime() const { return qBound(6, ourSettings->value("floodProtTime", 6).toInt(), 9999); } int Settings::qwFloodProtTime() const { return ourSettings->value("qwFloodProtTime", 600).toInt(); } int Settings::spamFloodProtTime() const { return ourSettings->value("spamFloodProtTime", 300).toInt(); } unsigned int Settings::queryInterval() const { return ourSettings->value("queryInterval", 1000).toUInt(); } int Settings::timeToSayHiAfterConnected() const { return ourSettings->value("timeToSayHiAfterConnected", 7).toInt(); } int Settings::timeToWaitForCountReply() const { return ourSettings->value("timeToWaitForCountReply", 7).toInt(); } bool Settings::developerMode() const { return ourSettings->value("developerMode", false).toBool(); } void Settings::save() { ourSettings->setValue("quakeFolder", quakeFolder()); ourSettings->setValue("botName", botName()); ourSettings->setValue("botPing", botPing()); ourSettings->setValue("botTopColor", botTopColor()); ourSettings->setValue("botBottomColor", botBottomColor()); ourSettings->setValue("botSpectator", botSpectator()); ourSettings->setValue("floodProtTime", floodProtTime()); ourSettings->setValue("queryInterval", queryInterval()); ourSettings->setValue("qwFloodProtTime", qwFloodProtTime()); ourSettings->setValue("spamFloodProtTime", spamFloodProtTime()); ourSettings->setValue("timeToSayHiAfterConnected", timeToSayHiAfterConnected()); ourSettings->setValue("timeToWaitForCountReply", timeToWaitForCountReply()); ourSettings->setValue("developerMode", developerMode()); QStringList list = serverList(); setServerList(list); }